Skip to content Skip to sidebar Skip to footer

How To Catch Creation Of Dom Elements And Manipulate Them With Jquery

I'm trying to devise a method of when adding a simple div element with a class and some data-* in it, it will replace it or add into it some other elements. This method should not

Solution 1:

You could use a DOM Level 3 Event, like DOMNodeInserted. This could look like:

$(document).bind('DOMNodeInserted', function(event) {
    // A new node was inserted into the DOM// event.target is a reference to the newly inserted node
});

As an alternative, you might checkout the .liveQuery jQuery plugin.

update

In referrence to your comment, have a look at http://www.quirksmode.org/dom/events/index.html, only browser which do not support it are the Internet Explorers of this this world (I guess IE9 does at least).

I can't say much about the performance, but it should perform fairly well.

Post a Comment for "How To Catch Creation Of Dom Elements And Manipulate Them With Jquery"