markzzz
markzzz

Reputation: 47945

google.maps.event.addListener and fall calls

I create this marker, and I'd like to attach and handler to the marker and one to an object inside the infowindow showed when I click on the marker:

var marker = new google.maps.Marker({
    position: posizione,
    map: map,
    title: "Title"
});

markerClick = function () {
    templateFinestra.find('.titolo').html("New Title");
    var prova = templateFinestra.find('.myLink');
    google.maps.event.addDomListener(prova, 'click', alert("Hello"));

    infoWindow.setContent(templateFinestra.html());
    infoWindow.open(map, marker);       
};

google.maps.event.addListener(marker, 'click', markerClick);

but when I click on marker, I see the alert! Why? And how can I create 2 separate handler? (one for the marker, one for the infowindow link opened when I click on marker).

Upvotes: 0

Views: 672

Answers (1)

Kevin B
Kevin B

Reputation: 95022

Because you are executing it immediately and giving it's return as a function (which it isn't).

google.maps.event.addDomListener(prova, 'click', function(){
    alert("Hello")
});

Upvotes: 1

Related Questions