title: How to detect click outside an element with a class selector Using Pure Javascript (without using Jquery)
body: <blockquote>
    <p>I want to detect clicking outside an element using class name as
    selector</p>
  </blockquote>
  
  <pre><code>&lt;div id="popOne" class="pop"&gt;...&lt;/div&gt;
  &lt;div id="popTwo" class="pop"&gt;...&lt;/div&gt;
  ...
  &lt;div id="popLast" class="pop"&gt;...&lt;/div&gt;
  
  
  &lt;script&gt;
      var popElement = document.getElementById("pop");
      document.addEventListener('click', function(event) {
          var isClickInside = popElement.contains(event.target);
          if (!isClickInside) {
              alert("Outside");
              //the click was outside the popElement, do something
          }
      });
  &lt;/script&gt;
  </code></pre>