Execute Script While Mouse Pointer is Over an Element in HTML



When the mouse pointer is moving over an element, the onmousemove attribute triggers. You can try to the following code to implement onmousemove attribute −

Example

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmousemove = "mouseMove()">
         This is demo heading.
      </h3>
     <p>Click above and then release.</p>
     <script>
        function mouseMove() {
        document.getElementById("myid").style.color = "red";
        }
     </script>
   </body>
</html>
Updated on: 2020-03-03T07:29:12+05:30

119 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements