The onmouse event is used to define the operation using mouse.
onmouse events in JavaScript are:
- onmouseover and onmouseout
- onmouseup and onmousedown
- onmouseenter and onmouseleave
-
onmouseover and onmouseout:
onmouseover and onmouseout events occur when the mouse cursor is placed over specific element
These events do not require mouse click to happen
<html><head><script type="text/javascript">functionover(){document.getElementById('key').innerHTML="Onmouseover event has occured";}functionout(){document.getElementById('key').innerHTML="Onmouseout event has occured";}</script></head><body bgcolor="cyan"><h2 id="key"onmouseover="over()"onmouseout="out()">Original Text</h2></body></html>chevron_rightfilter_noneOutput:
On loading webpage:

After placing mouse on element:

After removing mouse from the element:

-
onmouseup and onmousedown:
These events occur when a mouse click is encountered
<html><head><script type="text/javascript">functionup(){document.getElementById("img").src="up.png";}functiondown(){document.getElementById("img").src ="down.png";}</script></head><body bgcolor='yellow'><img id="img"src="img.png"onmouseup="up()"onmousedown="down()"width=500px></body></html>chevron_rightfilter_noneOutput:
On loading web page:

Occurence of onmousedown event:

Occurence of onmouseup event:

-
onmouseenter and onmouseleave
onmouseenter event occurs when the mouse is placed on the element and stays until the mouse is removed from the element
onmouseleave event occurs as soon as the mouse is removed from the element
These event do not require mouse click to happen
<html><head><script type="text/javascript">functionenter(){document.getElementById("img").src="enter.png";}functionleave(){document.getElementById("img").src ="leave.png";}</script></head><body bgcolor='yellow'><img id="img"src="img.png"onmouseenter="enter()"onmouseleave="leave()"width=500px></body></html>chevron_rightfilter_noneOutput:
On loading web page:

Occurence of onmouseenter event:

Occurence of onmouseleave event:

Recommended Posts:
- JavaScript | Events
- Difference between mouseover, mouseenter and mousemove events in JavaScript
- onKeyPress onKeyUp and onKeyDown Events in JavaScript
- CSS | pointer-events Property
- Node.js Events
- ES6 | Events
- Difference between DOMContentLoaded and load Events
- AngularJS | Events
- Keyboard Events in ElectronJS
- How to handle events in dynamically created elements in jQuery ?
- How to disable mouseout events triggered by child elements?
- jQuery Mouse Events
- How to use jQuery touch events plugin for mobiles ?
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | What is JavaScript ?
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.


