开发者

jQuery live() not working with click, works with mouseover

开发者 https://www.devze.com 2023-03-17 01:42 出处:网络
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:

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


Did you try:

$("#info_rightclick_top").live('click', function() {
        $("#info_rightclick").css('background', 'url(' + base_url + '/images/template/icons/map_rightclick_top.png)');
});

?

0

精彩评论

暂无评论...
验证码 换一张
取 消