Execute script when mouse button is pressed on HTML element?

王林
Release: 2023-08-29 20:53:14
forward
1361 people have browsed it

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.

Example

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>
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template