jQuery - override preventDefault() when click + ctrl pressed -


i using preventdefault() preventing default behavior of an anchor button, want make button default behavior when clicked keyboard ctrl button,

js code

$('a').click(function(e){     e.preventdefault(); }); 

html code

<a href="http://google.com">go best search engine</a> 

here playground: http://jsfiddle.net/skdua/

$('a').click(function(e) {     if (!e.ctrlkey) {         e.preventdefault();     } }); 

other intertesting options:

  • e.altkey - check if alt pressed
  • e.shiftkey - check if shift pressed
  • e.button - distinguish between right, left of middle mouse clicks
  • e.which - same above, works keyboard
  • full documentation here

one more note, asked documentation seem interested ;)

it's possible debug in jsfiddle - put debugger in js code , run usual. browser (i use chrome) stop on debugging line, , examine e object in watches:

enter image description here


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -