2

The code will will alert 1 when the text in the element is rendered. (comes from external JSON bit slow to load). I have it working. The only down side is that it will keep running even when its true.

I would like the loop to keep checking if the text has render every 5 seconds and stop looping when its done.

setInterval(function() {
 var text = $('#des1').text().length;
 if (text > 1) {
 setTimeout(function() {
 var e = $("a.urlcouint").length
 for (var t = 0; t < e; t++) {
 var l = document.getElementById("xurl").href;
 var n = l.indexOf("://") > -1 ? l.split("/")[2] : l.split("/")[0];
 n = n.split(":")[0];
 document.getElementById("xurl").innerHTML = n;
 document.getElementById("xurl").setAttribute("id", "xurldone");
 }
 }, 5);
 alert(1);
 } else {
 alert(0);
 }
}, 2000);
Oriol
291k71 gold badges459 silver badges535 bronze badges
asked Jul 31, 2016 at 21:55
1
  • Please post readable code when asking questions. Commented Jul 31, 2016 at 22:15

1 Answer 1

3

You need to look at the clearInterval method

var interval = setInterval(function () {
// do something here
 // When a condition is met and you want to kill the timeout
 clearInterval(interval);
}, 2000);
answered Jul 31, 2016 at 22:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.