title: Adding Event Listener on button - Javascript
body: <p>I'm trying to add an event listener on button added dynamically to a google maps infowindow.</p>
  
  <pre><code>  var contentString = '&lt;br&gt;&lt;/br&gt;' +
      '&lt;button type="button" class="btn btn-success" id="btnDirection"&gt;Get direction&lt;/button&gt; &lt;/div&gt;' +
       '&lt;button type="button" class="btn btn-success" id="btnDiscount"&gt;Related discount&lt;/button&gt; &lt;/div&gt;';
  
    var marker = new google.maps.Marker({
           map: map,
           animation: google.maps.Animation.DROP,
           position: place.geometry.location,
           icon: './Google_Maps_Markers/darkgreen_MarkerK.png'
    });
  
    google.maps.event.addListener(marker, 'click', function() {
          infoWindow.setContent(contentString);
          infoWindow.open(map, this);
  
          var btn = $(contentString).filter('#btnDirection'); 
          if(btn != null){
               for(var i=0; i&lt;btn.length; i++){
                    btn[i].addEventListener('click', function()           
                         { console.log("hello") });
               };
           };   
   });
  </code></pre>
  
  <p>Buttons are displayed on each infowindow, but when I click on nothing heppens.</p>
  
  <p>Could someone help me with this ?</p>