Skip to main content

Command Palette

Search for a command to run...

JavaScript mouse events

Published
1 min read
JavaScript mouse events
D

Dhiraj Khadka is a talented blogger and UI/UX designer from Sudurpaschim Nepal. With a passion for both blogging and design, Dhiraj brings a unique perspective to the online community.

Mouse Events

Any change in the state of an object is referred to as an Event. With the help of JS, you can handle events, i.e., how any specific HTML tag will work when the user does something.

● click

Fired when an element is clicked

element.addEventListener('click', ()=>{
//Code to be executed.. 
});

● oncontextmenu

Fired when an element is right-clicked

element.addEventListener('contextmenu', ()=>{
// Code to be executed..
});

● dblclick

Fired when an element is double-clicked

element.addEventListener('dblclick', ()=>{
/*Code to be executed..*/
});

● mouseenter

Fired when an element is entered by the mouse arrow

element.addEventListener('mouseenter', ()=>{
/*Code to be executed*/
});

● mouseleave

Fired when an element is exited by the mouse arrow

element.addEventListener('mouseleave', ()=>{
/* Code to be executed when  the event is fired*/
});

● mousemove

Fired when the mouse is moved inside the element

element.addEventListener('mousemove', ()=>{
/*Code to be executed when the event is fired*/
});