Execute a Script on Mouse Pointer Over an Element in HTML



The onmouseover attribute triggers when a mouse pointer moves over an element in HTML.

Example

You can try to run the following code to implement onmouseover attribute −

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmouseover = "display()">
         This is demo heading.
      </h3>
      <p>Keep the mouse cursor on the heading to change the color.</p>
      <script>
         function display() {
            document.getElementById("myid").style.color = "red";
         }
      </script>
   </body>
</html>
Updated on: 2020-05-30T23:25:36+05:30

311 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements