0
Can you fix this?
5 Answers
+ 2
let appear;
onload=()=>{
appear = document.querySelector('#empty');
}
function show() {
appear.innerHTML = Date();
}
+ 1
Abhay can you explain why my code doesn't work?
+ 1
EsaKurniawan sololearn keeps the javascript file in head ,therefore javascript is executed first and then the rest of html dom is loaded.
Javascript execution isn't much of a problem but when you make dom related queries like these "let appear = document.querySelector('#empty');
"
They fail since element with id empty doesn't exist yet .
Onload function handler delays the execution of javascript by checking if the html dom is loaded which solves that problem.
+ 1
Abhay thanks
0
<button onclick="this.textContent=new Date()">Show Hidden Date</button>