I want to reload div content, the results I found on the web didn't work for me. Help me My Code;
var x = new Date();
document.getElementById("refresh").innerHTML=x;
<div id="refresh">
</div>
I want to reload div content, the results I found on the web didn't work for me. Help me My Code;
var x = new Date();
document.getElementById("refresh").innerHTML=x;
<div id="refresh">
</div>
So your code should look like this:
setInterval(refresh, 1000);
function refresh() {
var x = new Date();
document.getElementById("refresh").innerHTML = x;
}
refresh();
you need to call the function continuously. It didn't work because in your code it only calls it once.
As my understood, you want to show system date on your html dom, right?
if so, you have to use some button, or you can use setInterval function. For example:
<div id="refresh">
</div>
<script>
setInterval(function() {
var x = new Date();
document.getElementById("refresh").innerHTML = x;
}, 300);
</script>
your code is fine and working I have checked Please check your Javascript library reference
Here is the working code
<button type="button"
onclick="document.getElementById('refresh').innerHTML = Date()">
Click me to display Date and Time.</button>
<div id="refresh">
</div>
For reload, u can use setInterval
<html>
<body>
<div id="refresh">
</div>
<script>
//When the document is loaded
document.addEventListener("load", myTimer);
//subsequent calls
setInterval(myTimer, 1000);
function myTimer(){
var d = new Date();
document.getElementById("refresh").innerHTML = d.toLocaleString();
}
</script>
</body>
</html>