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

有帮助吗?

解决方案

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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top