source code:
function toLove() {
$('div').append('<p>test</p>');
}
function startDO() {
var startID = setInterval(toLove(),1000);
}
function stopDO(){
clearInterval(startID);
}
$('#start').click(function(){
if ($(this).hasClass('running')){
$(this).removeClass('running');
stopDO();
}
else
{
$(this).addClass('running');
startDO();
}
});
<div>div block, watch below<br/>
when you click button DO it's append < p >test < / > inside this.
</div>
<input type="button" value="do" id="start" />
when I clicked my DO button, only first time I got append p,next it's only after second time click, but the it must be automaticly, by setInterval function...? Maybe troubles with toggle?