Reputation: 559
I am needing to refresh only one element using the JS console, rather than refreshing the whole page. I've got code that already works, but it depends on refreshing the page.
if (document.readyState === "complete") { vote(); }
function vote() {
//Do some stuff
setTimeout(function(){
location.reload();
}, 500);
}
Upvotes: 1
Views: 6835
Reputation: 1697
function reload(){
var container = document.getElementById("testDiv");
var newContent = "After reload";
container.innerHTML= newContent;
}
<button><a href="javascript: reload()">Reload</a></button>
<br/>
<div id="testDiv">
Before reload.
</div>
Upvotes: 2
Reputation: 164
What does refreshing one element mean? If you have a div with an id of element then you can just change the contents of that div using javascript and it will make the changes in your html. If the div contains "HI" then you can use document.getElementById("element").innerHTML and change it to whatever you want. Or you can change its attributes, you can add elements inside that div using javascript as well, what is it you are trying to do exactly? I assume that no matter what it is, you can just grab that element via its id and change it whenever you want it to refresh.
Upvotes: 1
Reputation: 138457
Looks like you just want to reload an iframe:
your normal html
<iframe src="page that should be reloaded.html">old browser</iframe>
<script>
function reload(){ document.getElementsByTagName("iframe")[0].reload();
}
</script>
Upvotes: 1