Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google places api autocomplete - adding click event

I'm appending a Search Results to the google places javascript api autocomplete.

So far I'm doing this:

var autocomplete;  
  function initialize() {
    var myLatlng = new google.maps.LatLng(40.738793, -73.991402);
    autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete'));
  }

later on I have this:

$('.pac-container').append( '<div class="j-search pac-item-refresh">Search Results</div>' );

$(document.body).on('click', '.pac-container .j-search', function(e) {
    console.log('click fired');
});

The problem? The click event never fires...

Any idea why? Anything wrong with my code?

like image 409
Darkagelink Avatar asked Oct 08 '13 14:10

Darkagelink


1 Answers

It seems that the click-event for .pac-container is cancelled by the Autocomplete-instance. Use mousedown instead.

like image 125
Dr.Molle Avatar answered Nov 19 '22 20:11

Dr.Molle