最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Refresh element using only JS console - Stack Overflow

programmeradmin1浏览0评论

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 === "plete") { vote(); }


function vote() { 
//Do some stuff

setTimeout(function(){ 
location.reload(); 
}, 500);
}

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 === "plete") { vote(); }


function vote() { 
//Do some stuff

setTimeout(function(){ 
location.reload(); 
}, 500);
}
Share Improve this question asked Sep 24, 2016 at 16:10 Jared BledsoeJared Bledsoe 5595 silver badges15 bronze badges 3
  • What do you mean with refreshing one elem?? – Jonas Wilms Commented Sep 24, 2016 at 16:15
  • I would like to reload only one specific element, say I had a div id with #element. Instead of refreshing the page, I would like to only refresh that specified element. – Jared Bledsoe Commented Sep 24, 2016 at 16:31
  • I think you dont understand the sense of HTML – Jonas Wilms Commented Sep 24, 2016 at 16:46
Add a ment  | 

3 Answers 3

Reset to default 2

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>

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>

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.

发布评论

评论列表(0)

  1. 暂无评论