Javatpoint Logo
Javatpoint Logo

Pressing and releasing the left mouse button in JavaScript

Pressing and releasing the left mouse button is an important feature of the mouse event function. The left side button uses for many functionalities to work, but the user uses the right side button for the same functionality. We can restrict the mouse event with the button click and release.

Syntax

  • The following syntax shows the mouse or mouse button press event using the "onmousedown" function.
  • The following syntax shows the mouse or mouse button release and go upside event using the "onmouseup" function.

Support browsers

The mouse event function supports many browsers. The following browsers are supported by pressing and releasing the left mouse button in javascript.

  • Crome
  • Edge
  • Firefox
  • Opera
  • Safari
  • IE

Examples

The mouse events work with different methods and different events. We can apply any functionality with mouseup and mousedown functions for the left button.

Example 1: the basic mouseup event uses the html tag and javascript function. Here we can use the mouseup function on the div tag with the input event data. Here, the function shows the value of the mouse's left, right, and middle button presses.

Output

The following output shows information after working the mouseup function for the left button.

Output1

Pressing and releasing the left mouse button in JavaScript

Example 2: the basic mouseup event with the javascript function and handler. If the left side button is pressed, then css style applies on the web page; otherwise, a notification shows on the web page.

Output

The following output shows information after working the mouseup function for the left button.

Pressing and releasing the left mouse button in JavaScript

Example 3: the basic mousedown event uses the html tag and JavaScript function. Here we can use the mousedown function on the div tag with the data. Here, the JavaScript function shows the event of the mouse's left, right, and middle button presses.

Output

The following output shows information after working the mouseup function for the left button.

Pressing and releasing the left mouse button in JavaScript

Example 4: the basic mousedown event used to press the button with the javascript function and handler. If the left side button is pressed, then css style applies on the web page; otherwise, a notification shows on the web page.

Output

The following output shows information after working the mousedown function for the left button.

Output1

Pressing and releasing the left mouse button in JavaScript

Output2

Pressing and releasing the left mouse button in JavaScript

Example 5: pressing and releasing the left button using button events.

Output

The following output shows information after working the mouseup function for the left button.

Output1

Pressing and releasing the left mouse button in JavaScript

Output2

Pressing and releasing the left mouse button in JavaScript

Example 6: pressing and releasing the left button using mousedown and mouseup events. It is used to help operate procedures using the html tag and JavaScript function.

Output

The following output shows information after working the mouseup function for the left button.

Output1

Pressing and releasing the left mouse button in JavaScript

Output2

Pressing and releasing the left mouse button in JavaScript

Conclusion

Pressing and releasing the left side of the mouse event helps to restrict user interaction. It helps the users to operate a mouse-related web and desktop development.







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