<div id='here'></div>
I am trying to refresh a certain div within a bunch of divs. The div content is basically generated by PHP along with data from a MySQL database in addition to many variables being sent with the help of an XMLHttpRequest.
The idea is to reload/refresh the div itself and not load a php file or to overwrite it with .text
or .html
. In this case, I cannot use .load('file.php')
What I have tried :
<script type='text/javascript'> function updateDiv() { document.getElementById("here").innerHTML = document.getElementById("here").innerHTML ; } </script>
and (for a every 3 second refresh) :
$(document).ready(function () { setInterval(function () { $('#here').load('#here')); }, 3000); });
Ideally, I would require something like :
function reloadDIV () {document.getElementById("here").innerHTML.reload} function reloadDIV () {$('#here').load(self)}
so that I can use it in a onClick :
<a onclick='reloadDIV ();'>reload div</a>
Use the textContent property to change the text of a div element, e.g. div. textContent = 'Replacement text' . The textContent property will set the text of the div to the provided string, replacing any of the existing content. Here is the HTML for the examples in this article.
Use this. $('#mydiv'). load(document. URL + ' #mydiv');
Use Ajax for this. Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server. The data will then (again via jQuery) be put inside the same div in question and replace old content with new one. e.g.
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" ); }
+ " #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 > *");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With