javascript/jQuery setInterval/clearInterval

前端 未结 1 1044
悲哀的现实
悲哀的现实 2021-01-06 06:06

i\'m using setInterval to check if a p(html paragraph) has a certain text value. if it has it i want to clear interval an continue code flow. i\'m using this in a jQuery plu

相关标签:
1条回答
  • 2021-01-06 06:31

    Use setTimeout instead of setInterval.

    Something like:

    var checkTextValue = setTimeout(function() {
        var textVal = $('p').text();
        if (textVal == 'expectedValue'){
            callback();
        } else {
            setTimeout(arguments.callee, 10);
        }
    },10);
    
    0 讨论(0)
提交回复
热议问题