javascript – How do I refresh a DIV content?

javascript – How do I refresh a DIV content?

To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in this case #here:

function updateDiv()
{ 
    $( #here ).load(window.location.href +  #here );
}
  • Dont disregard the space within the load element selector: + #here

This function can be called within an interval, or attached to a click event

For div refreshing without creating div inside yours with same id, you should use this inside your function

$(#yourDiv).load( #yourDiv > *);

javascript – How do I refresh a DIV content?

Complete working code would look like this:

<script> 
$(document).ready(function(){
setInterval(function(){
      $(#here).load(window.location.href +  #here );
}, 3000);
});
</script>

<div id=here>dynamic content ?</div>

self reloading div container refreshing every 3 sec.

Leave a Reply

Your email address will not be published.