jQuery: How to catch keydown + mouse click event?
22,897
You can check the .altKey
property, for example:
$(function() {
$("#targetDiv").click(function(event) {
if (event.altKey) {
//do something, alt was down when clicked
}
});
});
Comments
-
foreline over 3 years
I have a
div
element. I need to catch a mouse click on thisdiv
while alt-key (keyCode = 17) is pressed.Here is what i've got to catch key press:
// Html <div id="targetDiv">I want to put a ding in the universe.</div>
// Java-script $(document).ready(function(){ $(window).bind('keydown', function(event){ if ( 17 == event.keyCode ) { // How to catch mouse click on $('#targetDiv') ? } }); });
How to catch mouse click on div while alt-key is pressed?
-
foreline over 13 yearsNice solution to listen to click event first. Thanks.
-
Igorock over 9 yearsit's for Alt. For Ctrl use event.ctrlKey