Skip to content
Home » Web » jQuery » How to Hide an HTML Element after a Few Seconds

How to Hide an HTML Element after a Few Seconds

If you don't want an element to bother your visitors anymore after few seconds, you can do it in the document ready block.

$(document).ready(function() {
  ...
  setTimeout(function(){
    $("#hide-div").slideUp(2000);
  }, 3000);
});

In the above example, jQuery will take the element #hide-div to the background after 3 seconds with a 2 second slow motion (the default sliding time of slideUp() is 0.4 second).

Of course, you can also use hide() instead of slideUp() as you like, which will hide the element instantly without a slow motion.

Leave a Reply

Your email address will not be published. Required fields are marked *