I am using preventDefault() for preventing default behavior of an an anchor button, but I want to make this button to do default behavior when clicked with keyboard ctrl button,
JS code
$('a').click(function(e){
e.preventDefault();
});
HTML code
<a href="http://google.com">Go to the best search engine</a>
Here is the playground: http://jsfiddle.net/sKDuA/
$('a').click(function(e) {
if (!e.ctrlKey) {
e.preventDefault();
}
});
Other intertesting options:
e.altKey - to check if Alt was pressede.shiftKey - to check if Shift was pressede.button - to distinguish between right, left of middle mouse clickse.which - same as above, but also works for keyboardOne more note, as you asked about documentation so seem to be really interested ;)
It's possible to debug in jsfiddle - just put debugger in your js code and run as usual. Your browser (I use Chrome) would stop on the debugging line, and you could examine the e object in the watches:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With