HTML | DOM MouseEvent
Events that occur when the mouse interacts with the HTML document falls under the category of MouseEvent property.
Event Types:
- onclick: The event occurs when the user clicks on an element.
- onmousedown: The event occurs when the button pressed over an element.
- onmouseenter: The event occurs when the pointer is moved onto an element.
- onmouseout: The event occurs when a user moves the mouse pointer out of an element, or out of one of its children.
- onmouseup: The event occurs when a user releases a mouse button over an element.
- oncontextmenu: This event occurs on right-click on an element.
- ondblclick: This event occurs on double-click on an element.
- onmouseleave: When pointer is moved out of an element.
- onmousemove: This event occurs while pointer move over element.
- onmouseover: This event occurs when the pointer move over an element, or its children.
Syntax:
- onmouseup property:
<element onmouseup="ID">
- onmousedown property:
<element onmousedown="ID">
- onclick property:
<element onclick="ID">
- oncontextmenu property:
<element oncontextmenu="ID">
- ondblclick property:
<element ondblclick="ID">
- onmouseenter property:
<element onmouseenter="ID">
- onmouseleave property:
<element onmouseleave="ID">
- onmousemove property:
<element onmousemove="ID">
- onmouseout property:
<element onmouseout="ID">
- onmouseover property:
<element onmouseover="ID">
Example-1: Below program illustrate onmousedown and onmouseup property.
<!DOCTYPE html> <html> <body> <center> <h3>GEEKS FOR GEEKS</h3> <p id="myP" onmousedown="mouseDown()" onmouseup="mouseUp()"> . The mouseDown() function works when the mouse button is pressed down over this paragraph and sets the color of the text to 'Yellow'. The mouseUp() function works when the mouse button is released and sets the color of the text to 'Red'. </p> <script> function onmouseDown() { // using onmousedown property document.getElementById("myP").style.color = "yellow"; } function mouseUp() { // using onmouseup property document.getElementById("myP").style.color = "red"; } </script> </center> </body> </html> |
chevron_right
filter_none
Output:
Initial:

mouseDown:

mouseUp:

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Opera
- Safari
Recommended Posts:
- HTML | DOM MouseEvent clientX Property
- HTML | DOM MouseEvent screenY Property
- HTML | DOM MouseEvent pageX Property
- HTML | DOM MouseEvent clientY Property
- HTML | DOM MouseEvent offsetY Property
- HTML | DOM MouseEvent offsetX Property
- HTML | DOM MouseEvent pageY Property
- HTML | DOM MouseEvent relatedTarget Property
- HTML | DOM MouseEvent screenX Property
- HTML | DOM MouseEvent buttons Property
- Javascript | MouseEvent which Property
- JavaScript | MouseEvent shiftKey Property
- Javascript | MouseEvent getModifierState() Method
- JavaScript | MouseEvent Button Property
- Javascript | MouseEvent ctrlKey Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



