jQuery .delegate() not working on load and changeData events

后端 未结 3 1657
轻奢々
轻奢々 2021-01-13 05:39

Can someone enlighten me on the jQuery delegate, what events are handled and what aren\'t. The follow code doesn\'t work

$(\"#browser\").delegate( \".photo\"         


        
相关标签:
3条回答
  • 2021-01-13 05:52

    These events do not bubble, so they cannot be used with live or delegate.

    0 讨论(0)
  • 2021-01-13 06:08

    Not:

    $("#browser").delegate( ".photo", {
        "load": function(e) {
            alert("photo loaded");
        }
    });
    

    But:

    $("#browser").delegate( ".photo", "load",
        function(e) {
            alert("photo loaded");
    });
    

    And you cannot use live and delegate with those events, because they don't bubble.

    0 讨论(0)
  • 2021-01-13 06:10

    For newer versions of jQuery, where the .on() method is favored before the .delegate() or .live() methods, it won't work in this way, too

    // wrong
    jQuery(selector).on('load', 'img', myFunc)
    

    because the load event does not bubble

    make it like this

    jQuery(selector).find('img').on('load', myFunc)
    
    0 讨论(0)
提交回复
热议问题