I'm using jQuery to listen to DOMSubtreeModified event, and then execute a function. What I need is a way to only run a function once per event burst. So in this case, the event will only run 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 are there just to emulate my problem. I need a solution without changing the setTimeout code. The problem I'm having is that I get burst of DOMSubtreeModified events, and I need to get only one per burst.