Home >Web Front-end >HTML Tutorial >Execute script when mouse button is pressed on HTML element?
Use the onmousedown attribute in HTML to execute a script when the mouse button is pressed on an element.
You can try running the following code to implement the onmousedown attribute -
<!DOCTYPE html> <html> <body> <h3 id = "myid" onmousedown = "mouseDown()" onmouseup = "mouseUp()"> This is demo heading. </h3> <p>Click above and then release.</p> <script> function mouseDown() { document.getElementById("myid").style.color = "yellow"; } function mouseUp() { document.getElementById("myid").style.color = "blue"; } </script> </body> </html>
The above is the detailed content of Execute script when mouse button is pressed on HTML element?. For more information, please follow other related articles on the PHP Chinese website!