To do this we will be using the normal setInterval in jQuery. We will create an element to be considered to be our container div. And by using setInterval, we will refresh the content that we created dynamically to our container div. I hope you will like this.
Using the code
To work with it, load your jQuery reference first. I am using the following version of jQuery.
- <script src="http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js"></script>
Create a container div
- <div id='container'></div>
So now we can do our script part.
Implementation
Here's the scripts:
- $(document).ready(
- function() {
- setInterval(function() {
- var randomnumber = Math.floor(Math.random() * 20);
- var html='';
- for(i=0;i<randomnumber;i++)
- {
- html+='<p>'+ randomnumber+ '</p>';
- }
- $('#container').html(html);
- }, 1000);
- });
As you can see, we are creating some random numbers less than 20.
- var randomnumber = Math.floor(Math.random() * 20);
And assigning the random value to the dynamically created p tag.
- html+='<p>'+ randomnumber+ '</p>'
Now we need to style our p tag as in the following:
- p {
- border: 1px solid #ccc;
- border-radius: 5px;
- height: 18px;
- width: 18px;
- padding: 5px;
- text-align: center;
- background-color: #999;
- color: #fff;
- float: left;
- }
That is all, it is time to run our code.
jsfiddle link: Loading or refreshing a div content jsfiddle
Output

Conclusion
I hope you liked this article. Please share with me your valuable feedback. Thanks in advance.


Shridhar SharmaPosted Aug 5, 2015, 6:37 AM EDT
nice share :)
Sibeesh VenuTOP 100Posted Aug 4, 2015, 8:55 PM EDT
Santhakumar Munuswamy Thank you
Santhakumar MunuswamyPosted Aug 4, 2015, 6:06 PM EDT
Good Article. Thanks for sharing :)
Sibeesh VenuTOP 100Posted Aug 4, 2015, 2:37 AM EDT
Rajeesh Menoth Thanks buddy
Rajeesh MenothPosted Aug 4, 2015, 1:30 AM EDT
Good One Sibeesh Venu
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:29 PM EDT
Upendra Pratap Shahi Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:28 PM EDT
Nilesh Jadav Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:28 PM EDT
Chervine Bhiwoo Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:24 PM EDT
Pankaj Kumar Choudhary Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:24 PM EDT
Santhakumar Munuswamy Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 9:24 PM EDT
Rakesh Chavda Thank you
Upendra Pratap ShahiPosted Aug 3, 2015, 9:21 PM EDT
nice sir..
Nilesh JadavPosted Aug 3, 2015, 8:22 PM EDT
Nice one sir incredible :)
Chervine BhiwooPosted Aug 3, 2015, 7:27 PM EDT
Nice work
Pankaj Kumar ChoudharyTOP 100Posted Aug 3, 2015, 5:21 PM EDT
Nice Explain Sir......
Santhakumar MunuswamyPosted Aug 3, 2015, 10:41 AM EDT
Nice article. Thanks for sharing
RakeshPosted Aug 3, 2015, 7:27 AM EDT
Nice one
Sibeesh VenuTOP 100Posted Aug 3, 2015, 4:17 AM EDT
Neeraj Kumar Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 4:17 AM EDT
Vignesh Mani Thank you
Sibeesh VenuTOP 100Posted Aug 3, 2015, 4:17 AM EDT
Gopi Chand Thank you
Neeraj KumarPosted Aug 3, 2015, 3:17 AM EDT
Nice work
Vignesh ManiTOP 100Posted Aug 3, 2015, 2:36 AM EDT
Nice one
Gopi ChandPosted Aug 3, 2015, 2:12 AM EDT
Nice work
Sibeesh VenuTOP 100Posted Aug 3, 2015, 2:00 AM EDT
Rajeesh Menoth Thank you
Rajeesh MenothPosted Aug 3, 2015, 1:33 AM EDT
Good One Sibeesh Venu