jeudi 21 décembre 2017

Clear and Restart setInterval

In my setInterval if the div contains 4) PLACEHOLDER it will prepend an image if the div dose not contain those words it will clear the interval lets say the div text is true and is 4) PLACEHOLDER so the interval is cleared but then the text changes to 5) PLACEHOLDER How can I restart the Interval to check the if statement again ?

var interval = 500;
var timer = window.setInterval(function() {

   if(jQuery("div.text-split-original").text().trim().indexOf('4) PLACEHOLDER') != -1) 
{
  $('.scar__label').prepend('<img src="smiley.gif" />');
  clearInterval(timer);

}
}, interval);

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire