Javascript DOM HTML Div handle mouse down event and get pressed mouse button

Description

Javascript DOM HTML Div handle mouse down event and get pressed mouse button

View in separate window

<!DOCTYPE html>
<html>
<body>

<div onmousedown="WhichButton(event)">Click this text<p>
0 Specifies the left mouse-button<br>
1 Specifies the middle mouse-button<br>
2 Specifies the right mouse-button</p>
</div>//  w w w.j  a  v  a 2  s  .  co m
<p id="demo"></p>
<script>
function WhichButton(event) {
  document.getElementById("demo").innerHTML = "You pressed button: " + event.button;
}
</script>

</body>
</html>



PreviousNext

Related