Pressing and releasing the left mouse button in JavaScriptPressing 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
Support browsersThe mouse event function supports many browsers. The following browsers are supported by pressing and releasing the left mouse button in javascript.
ExamplesThe 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 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. 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. 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 Output2 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 Output2 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 Output2 ConclusionPressing 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. |