Reputation: 563
I don't know if this is possible but I'd like to refresh the contents in a div when a button is clicked.
Example:
<div id="div">
Some contents
</div>
<input type="button" value="button" onClick="div.refresh()"/>
I'm not trying to change the contents of the div just to refresh only that part of the page.
Is this possible?
Upvotes: 1
Views: 179
Reputation: 16115
In the following example, the jQuery load function returns the content of the site page.html
, searches the DOM element (here with id div2
) and remembers the HTML content. The HTML content of the main selected DOM element (here with id div1
) is replaced with the new content.
$('#div1').load('page.html #div2');
The following code will replace your div
html with the current content.
function div_refresh() {
$('#div').load(window.location.href + ' #div');
}
Also see my example.
Upvotes: 1
Reputation: 120178
Im not trying to change the contents of the div just to refresh only that part of the page.
That doesn't make much sense. If you want to refresh part of the page, you want to change content somewhere...
Anyway, it's certainly possible.
if your div has attribute id="myDiv"
then you would do something like
$('#myDiv').html('updated content');
as a simple example. The $('#myDiv')
has jquery select the element with id myDiv
, and the html
call changes to value in the div...Documentation here.
Again, that's a really simple example of how to change the content of just a div with jQuery....
Upvotes: 0