I canβt believe that no one has told you about this: you are using Mutation Events, which is deprecated as described in here .
As recommended on this page, you should use the Mutation Observer .
Below is a snippet that I rewrote js code using a Mutation Observer based on the original example
$(function () { var a = 0; $("#test2").append('<br>I Ran'); var id = setInterval(function () { console.log("running"); }, 1000);
<!DOCTYPE html> <html lang="en"> <header> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script src="site.js"></script> </header> <body> <div id="test"> <div id="2" class="test"> <div id="test2">help</div> </div> </div> <div id="del">Press here to remove</div> </body> </html>
source share