Display an Element for 5 Seconds using JavaScript
Submitted by alpha_luna on Monday, July 11, 2016 - 15:39.
In this tutorial, we are going to show you on how to Display an Element for 5 Seconds using JavaScript. We are going to use JavaScript library for creating this simple tutorial that can display any element for 5 seconds.
Features of this simple tutorial.
After compiling the source code above, there’s a short text “Welcome to the Sourcecodester Tutorials!” is displayed in your current browser for five (5) seconds and it will be hidden from the user after five (5) seconds. We have quick explanation below of the source code above:
- The element (or any element) fade into a display.
- The element (or any element) fade out after 5 seconds and this going to hide it.
Creating Markup
This simple source code using jQuery execute to display the element for 5 seconds. Let’s take a look at the following sample of source code below. Kindly copy and paste this source code to your BODY tag of your page.- We have our div and the id “message_display” – it will help us to access it using jQuery.
- In our div, we have an Inline style of “display:none” – to make sure that our div and the text inside it will be hidden to the user.
- We include the jQuery library file from the jQuery CDN to execute the program.
- We are going to use the ready function in the short script to make sure that our source code does not execute automatically until the page or the browser has been loaded.
- If the browser or the current page is loaded, the script will be executed then the div will display using the fadeIn function within five (5) seconds, and it has delay function to fadeOut by five (5) seconds.
Add new comment
- 726 views