Update DOM after insert in jQuery

后端 未结 3 1762
猫巷女王i
猫巷女王i 2020-12-21 07:52

Let\'s say I use jQuery to load new content into a specific DIV element. If I now want to catch events from inside that DIV element, I assume the DOM has to be updated someh

相关标签:
3条回答
  • 2020-12-21 08:33

    jQuery uses "live" events to deal with things happening in dynamically added DOM elements without having to manually add handlers after a content-update.

    0 讨论(0)
  • 2020-12-21 08:35

    Since jQuery 1.7.x the .live() method is deprecated. Use .on() to attach event handlers. If you are using an older version you should use .delegate() in preference to .live().

    As mentioned in the help, the format does not change a lot like shown in this example:

    $(selector).live(events, data, handler); // jQuery 1.3+
    $(document).delegate(selector, events, data, handler); // jQuery 1.4.3+
    $(document).on(events, selector, data, handler); // jQuery 1.7+

    So since 1.7.x, both, delegate and live have been superseeded by on.

    0 讨论(0)
  • 2020-12-21 08:45

    Use live like this:

     $(".view").live("click",function(){
          $(this).parent().load("view");
        });
    
    0 讨论(0)
提交回复
热议问题