HTML event attribute onmousedown








The onmousedown attribute event is triggered when pressing down a mouse button on the element.

The order of events related to the onmousedown event for mouse button:

  • onmousedown
  • onmouseup
  • onclick or oncontextmenu for right click




What's new in HTML5

None.

Syntax

<element onmousedown="script or Javascript function name">

Supported Tags

All HTML elements, EXCEPT:

<base>, 
<bdo>, 
<br>, 
<head>, 
<html>, 
<iframe>, 
<meta>, 
<param>, 
<script>, 
<style>, 
<title>




Browser compatibility

onmousedown Yes Yes Yes Yes Yes

Example

<!DOCTYPE html>
<html>
<body>
<!--from w  ww .  j  a  va 2s  .c o  m-->
<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! 
</p>

<script>
function mouseDown() {
    console.log("down");
}

function mouseUp() {
    console.log("up");
}
</script>

</body>
</html>

Click to view the demo