event.which Property - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:event.which

Description

The event.which property returns which keyboard key or mouse button was pressed for the event.

Syntax

Parameter Require Description
event Required. The event parameter comes from the event binding function

The following code shows how to Return which keyboard key was pressed:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("div").mousedown(function(event){
        $("div").append("<br>Mouse button pressed: " + event.which);
    });//from  w ww.  j  a v a2  s .c  o  m
});
</script>
</head>
<body>

<div style="border:1px solid black;width:200px;height:200px;">Press mouse buttons.</div>

</body>
</html>

Related Tutorials