I use jQuery to listen for the DOMSubtreeModified event, and then execute the function. What I need is a way to run only one function in a single event package. Thus, in this case, the event will work only after 1 second and again after 3 seconds. What is the best way to do this?
JQuery
$(function(){ setTimeout(function(){ $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; },1000); setTimeout(function(){ $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; $('#container')[0].innerHTML = 'test'; },3000); $('#container').bind('DOMSubtreeModified',function(){ console.log('event'); functionToRun(); }); });
HTML
<div id="container"></div>
Update
The setTimeout function is intended only to emulate my problem. I need a solution without changing the setTimeout code. The problem I am facing is that I am getting a DOMSubtreeModified event burst and I only need to get one package.
source share