javascript - How to detect a keypress AND a mouseover at the same time -
okay can detect mouseover using .on('mouseover')
and can detect keypresses using
$(document).keypress(function(e) { console.log(e.which); }
but how detect image mouse hovering on when press button?
the idea able delete image pressing d while hovering on it. ideas ?
you can toggle class or data-attribute shows 1 being hovered
$('img').hover(function(){ $(this).toggleclass('active'); // if hovered has class active }); $(document).keypress(function(e) { if(e.which == 100){ $('.active').remove(); // if d pressed remove active image } });
Comments
Post a Comment