I have a problem of jQuery’s live() function not working with click, mousedown but works with ‘mouseover, mouseout`. For example the code below does not work:
Not working:
$("#info_rightclick_top").live('click', function() {
marker_search_location.setPosition(rightclick_latlng);
});
Working:
$("#info_rightclick_top").live('mouseover', function() {
$("#info_rightclick").css('background', 'url(' + base_url + '/images/template/icons/map_rightclick_top.png)');
});
I am using live() instead of click() because the div being selected does not exist when the document is loaded and is generated dynamically. I dont get it why using the click event on live() doesnt work? Any ideas?
EDIT:
The above code that was not working previously now works when I put it in a Google Maps Listener… why is this so?
google.maps.event.addListener(map, "rightclick", function(event) {
$("#info_rightclick_top").click(function(e) {
alert("asd");
});
});
Maybe it’s Event Bubbling. You should return false in your live function to prevent it.
More details