Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove new div after 5 seconds

Tags:

jquery

i want to add a div and after 5 seconds remove it. i tried

$("#mainContentTD").prepend("<div style='color: #038a00; padding-bottom:10px;'>Your detailes where sucsesfuly... </div>").delay(5000).remove("this:first-child");
like image 472
eyalb Avatar asked Dec 06 '10 07:12

eyalb


People also ask

How do you show divs after 5 seconds?

Use noscript tag and put div in it to display when java script is disabled in browser. Show activity on this post. Show activity on this post. The below code worked for me, if you are intending to show the Div for a few seconds...


1 Answers

You can use setTimeout like this:

setTimeout(function(){
  $('#divID').remove();
}, 5000);

The 5000 (ms) means 5 seconds. You should replace divID with your own div/element id.

You can make sure that the div exists first using length:

setTimeout(function(){
  if ($('#divID').length > 0) {
    $('#divID').remove();
  }
}, 5000)
like image 195
Sarfraz Avatar answered Sep 18 '22 15:09

Sarfraz