Computer >> Computer tutorials >  >> Programming >> HTML

Execute a script when the mouse wheel rolls up or down over an element in HTML?


The onwheel attribute triggers when the mouse wheel rolls up or down over an element. You can try to run the following code to implement onwheel attribute −

Example

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onwheel = "mouseWheel()">
         This is demo heading.
      </h3>
      <p>Click above and use mouse wheel to change the heading color.</p>
      <script>
         function mouseWheel() {
            document.getElementById("myid").style.color = "red";
         }
      </script>
   </body>
</html>