Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide/Remove a tag after X seconds with jquery

I am wondering how can I hide/remove a tag after a certain amount of time. Is there some built in thing or do I do use threading(if javascript can do this?)

like image 241
chobo2 Avatar asked Aug 20 '09 23:08

chobo2


2 Answers

You don't even need jQuery for the "5 seconds" part: JavaScript's built-in setTimeout function will do the trick. Incorporating jQuery for the DOM manipulation, you get:

setTimeout(function() {
  $("#the-tag-you-want-to-remove").remove();
}, 5000);

Here the 5000 represents 5000 milliseconds, or 5 seconds. You can pass setTimeout an existing function or (as in this case) an anonymous function.

like image 73
VoteyDisciple Avatar answered Oct 02 '22 03:10

VoteyDisciple


Try to use .delay() function

http://api.jquery.com/delay/

like image 37
Igor Avatar answered Oct 02 '22 01:10

Igor