jQuery Event How to - Check if shift key pressed when clicking mouse








Question

We would like to know how to check if shift key pressed when clicking mouse.

Answer


<!-- ww w.jav a 2s  . co  m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $('.edit').click(function(e) {
        if (e.shiftKey) {
            console.log("shift+click")
        } 
    });
});
</script>
</head>
<body>
  <a href="#" class="edit">click here</a>
</body>
</html>

The code above is rendered as follows: