Is there a jquery event that fires when a new node is inserted into the dom?

后端 未结 5 1693
故里飘歌
故里飘歌 2020-11-27 04:05

Is there an event jquery fires on a dom element when it is inserted into the dom?

E.g. lets say I load some content via ajax and add it to the DOM and in some other

5条回答
  •  忘掉有多难
    2020-11-27 05:05

    The .livequery() plugin still serves this niche need, like this:

    $('.myClass').livequery(function() {
      alert('.myClass added to dom');
    });
    

    If you pass it just a callback function like above, it'll run for each new element it finds, both initially and as they're added. Inside the function this refers to the just-added element.

    .live() listens for events that bubble, so doesn't fit this "when elements are added" situation, in that respect, .livequery() (the plugin) wasn't completely replaced by the addition of .live() to core, only the event bubbling portion (for the most part) was.

提交回复
热议问题