title: Listen to click on ONLY on the map of Google Maps embed
body: <p>I have a Google Map with markers on it. When the user clicks on a marker, a sidebar slides out by adding a class to the sidebar element.</p>
  
  <p>Now, I want to hide the sidebar when the user clicks somewhere on the map.</p>
  
  <p>I added an click event listener on the map, but it also gets triggered when the user clicks on the marker. So the sidebar is shown and hidden immediately.</p>
  
  <p>Marker event listener:
  <code>maps.event.addListener(marker, 'click', markerClicked);</code></p>
  
  <p>Map event listener:
  <code>maps.event.addListener(map, "click", function() {</code></p>
  
  <p>How can I detect a click ONLY the map?</p>
  
  <p><strong>---EDIT---</strong></p>
  
  <p>Allright, some code on request:</p>
  
  <p>For every marker I add to the map I activate a click event listener like this:
  <code>google.maps.event.addListener(marker, 'click', markerClicked);</code></p>
  
  <p>The <code>markerClicked</code> function contains the following code which opens a sidebar:</p>
  
  <pre><code>var markerClicked = function() {
      $('.sidebar--slide-in').addClass('sidebar--slide-in-active');
  };
  </code></pre>
  
  <p>Also when the map is created I activate a click event listener for the map, like this:</p>
  
  <pre><code>google.maps.event.addDomListener(map, "click", function() {
  
  });
  </code></pre>
  
  <p>The marker click listener works like a charm. When a marker is clicked, it returns the clicked marker. When the map is clicked nothing happens.</p>
  
  <p>The map click event listener however returns an object when the map is clicked, but also when a marker is clicked.</p>
  
  <p>When the map is clicked(not when a marker is clicked!) I want to close the sidebar. How do I do this?</p>
  
  <p><strong>---EDIT 2---</strong></p>
  
  <p>I failed to mention I use custom markers. I thought this didn't affect the problem in any way. It appears it does. I copied the codepen from @Dekel and added my custom marker in it.</p>
  
  <p><a href="http://codepen.io/nieknijland/pen/QKyaxw" rel="nofollow">http://codepen.io/nieknijland/pen/QKyaxw</a></p>
  
  <p>Now when you click the marker both alerts are triggered. I just want te marker alert te be triggered, not the map click event.</p>