View video tutorial

HTML onmousedown Attribute

HTML

The HTML onmousedown attribute is an event handler that triggers the script to execute when the mouse button is pressed on a specific element.

Definition and Usage


➔ It fires as soon as the button is pressed, which is earlier than the onclick event in the event sequence.

➔ The onmousedown event is triggered immediately after the button is pressed, which is earlier than the onclick event in the event sequence.

Single left or middle mouse button click event sequence:

  • 1 onmousedown - is triggered when the mouse button is initially pressed down.
  • 2 onmouseup - is triggered when the mouse button is released.
  • 3 onclick - is fired after both mousedown and mouseup events.

Double left click event sequence:

  • 1 onmousedown - is triggered when the mouse button is initially pressed down.
  • 2 onmouseup - is triggered when the mouse button is released.
  • 3 onclick - is triggered after both mousedown and mouseup events.
  • 4 onmousedown - is triggered when the mouse button is initially pressed down.
  • 5 onmouseup - is triggered when the mouse button is released.
  • 6 onclick - is triggered after both mousedown and mouseup events.
  • 7 ondblclick - is triggered after two complete click sequences within about 300-500 milliseconds.

Right click event sequence:

  • 1 onmousedown - is triggered when the mouse button is initially pressed down.
  • 2 onmouseup - is triggered when the mouse button is released.
  • 3 oncontextmenu - is triggered when the right mouse button is pressed and released.

Mouse movement event sequence:

  • 1 onmouseover - is triggered when the pointer moves over an element or one of its descendants.
  • 2 onmouseenter - is triggered when the pointer enters the element, not its descendants (there is no bubble in the DOM hierarchy).
  • 3 onmousemove - is triggered repeatedly when the pointer moves over an element.
  • 4 onmouseout - is triggered when the pointer moves out of an element or into one of its descendants.
  • 5 onmouseleave - is triggered only when the pointer explicitly leaves the element's bounds, not outside its descendants.

Applies to

This attribute can be used on the following element.

Attribute Element
onmousedown All visible elements