Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to ignore mouse interaction on overlay image using JavaScript ?

  • Last Updated : 22 Jun, 2020

Ignoring mouse interaction on overlay image can be controlled by a CSS property namely pointer-events.
It is a property that defines if an element of the page will react to the pointer-events.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

pointer-events: auto\none;

Example: The following example demonstrates the use of pointer-events property.




<!DOCTYPE html>
<html>
  
<head>
  <title>CSS pointer events</title>
  
  <style>
    .main {
      position: relative;
      width: 450px;
      font: 25px Verdana;
    }
  
    .overlay {
      position: absolute;
      left: 0px;
      top: 0;
      width: 225px;
      height: 225px;
    }
  
    .pointer-events-none {
      pointer-events: none;
    }
  </style>
  
  <script>
    window.onload = function () {
      document.getElementById(
        "enable-disable-pointer-events")
        .onclick = function () {
          document.getElementById("overlay")
            .className = "overlay " 
            + ((this.checked) ? 
            "pointer-events-none" : "");
      };
    };
  </script>
</head>
  
<body>
  <div class="main">
      <img
        src=
    GeeksforGeeks: A computer 
    Science portal for Geeks.
      
    <div id="overlay" class="overlay"></div>
      
    <p>
      <input id="enable-disable-pointer-events" 
          type="checkbox">
      <label for="enable-disable-pointer-events">
        Disable pointer events for image
      </label>
    </p>
  </div>
</body>
  
</html>

Output:
When the checkbox was not selected:

When the checkbox is selected:

Final Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :