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