Question

I would like to know how I can listen to the DOM when a SPECIFIC element is added, and then act upon it.

After the DOM s loaded initially, there is a div(.myElement) that is loaded long afterwards:

<div class="container">.
   ...
   ...
   ...
   <div class="myElement"></div>
</div>

 $("div.container").bind("DOMNodeInserted",function(){
        alert("div.myElement has just been appended");
    });

Now the moment the element:

<div class="myElement"></div>

is added to the parent div(container), i want to run a function. How do i do that?

Thank you

Was it helpful?

Solution

You can't. DOmNodeInserted has been removed and there's no alternative.

Solutions to provide a similar behavior are

  • pulling, ie testing with setInterval for additions. That would degrade performances.
  • changing the code inserting the element.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top