Javatpoint Logo
Javatpoint Logo

How to use the mousedown event in javascript

The mousedown event uses the mouse movement on the web page using the javascript functionality. The mouse-down event works on the laptop's mouse, or single mouse click. If we press the on a laptop, the mouse down event starts its handling functionality.

Syntax

The following syntax shows the mouse or mouse button press-down event using the "onmousedown" function.

The following syntax shows the mouse or mouse button press-down event with the "mousedown" function using the addEventListener event.

The following syntax uses a mousedown event with a javascript function.

Examples

The given examples show the mousedown events with the functionality.

Example 1: the basic mousedown event with the html tag and javascript function. Here we can use the mousedown function on the div tag. Its function uses in the javascript tag with the style tag to change height, colour and others.

Output

The following output shows the web page after working the mousedown function.

How to use the mousedown event in javascript

Example 2: the basic mousedown event with the javascript function and handler. We can use the object of the html element id and use the function in the javascript.

Output

The following output shows the web page after working the mousedown function.

How to use the mousedown event in javascript

Example 3: the mousedown event used for Windows with the javascript function and handler. We can use the window object with the mousedown event with the handler name.

Output

The following output shows the web page after working the mousedown function.

How to use the mousedown event in javascript

Example 4: The basic mousedown event with the javascript function and handler. We can use the object of the html element id and use the function in the javascript. The mouse-down event uses the addEventListener event in the script tag.

Output

The following output shows the web page after working the mousedown function.

How to use the mousedown event in javascript

Example 5: the example uses a mousedown event with the javascript function and its handler. We can use the object of the html body tag using id. The mouse-down event uses the addEventListener event in the script tag.

Output

The following output shows the web page after working the mousedown function.

How to use the mousedown event in javascript

Conclusion

The mousedown event works when we press the mouse button but does not release the button. We can use it for the mouse user's application and apply functionality on the web page. It is easy for laptop users, desktops and other mouse applications.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA