0

I need to replace a text within div that says "Please wait..." with "Ok.Its done." after a random delay.Please help.Thanks in advance.

4
  • possible duplicate of : stackoverflow.com/questions/121817/… Commented Jul 28, 2010 at 13:30
  • use setTimeout to update the div's text Commented Jul 28, 2010 at 13:35
  • @monO: That question does not mention jQuery or a random delay, I think. Commented Jul 28, 2010 at 13:36
  • @peter: True, definitly not a duplicate; I'll leave the link just for reference though! Commented Jul 28, 2010 at 13:51

3 Answers 3

3

Try this:

$("#foo").text("Please Wait...")
         .delay(Math.random() * 1000) // between 0 and 1000 milliseconds
         .queue(function(q){
             $(this).text("okay, it's done");
             q();
         });
Sign up to request clarification or add additional context in comments.

2 Comments

You should call the next function from any queue function or the queue for this element is forever stuck, like this: .queue(function(n){ $(this).text("okay, it's done"); n(); });
Thank you. It was helpful and I accept your soultion.Thanks @Nick for timely suggestions
2
<script type="text/javascript"> 
window.onload = function () { 
  setTimeout(function () { 
    var div = document.getElementById('yourDiv'); 
    div.innerHTML = "OK. It's done.";  
  }, 10000); 
} 
</script> 

11 Comments

It's not using jquery as i can see.
@antyrat - A solution doesn't need to... Use jQuery if it helps, don't if it doesn't.
Please don't use window.onload - either use some DOM-ready event or simply place the script below any referenced elements.
@Nick, I wouldn't say it's drastic. We really don't know much because the OP hasn't said much. We don't know that the div has an ID, we don't know if the OP is already using jQuery for other tasks etc. Depending on the situation I might agree with you but given that we simply don't know I thought it best to answer the question in jQuery. If the question was not tagged with "jQuery" I would have gone for a plain JS approach too.
If you wanted you could still use jQuery within the setTimeout function, as in var div = $('#yourDiv').text("Ok. It's done.");. But there is no good reason to use jQuery for a simple for a simple delay. To me that is tantamount to saying "Why use var x=5; when you could write $.extend(variables, {x: 5}); in jQuery!?"
|
-1

in jQuery, it would be:

$("myDiv").html("new content");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.