+ 1
¿Why this outputs "null"
any info will help https://code.sololearn.com/WKrsa0wEg7LL/?ref=app
2 Respostas
+ 7
wrap your js in a window.onload. The DOM has not been created yet when your code is running as the JS tab is injected into the head of the html page and runs prior to the body, so your divs do not exist at that time. Also, you're just trying to get the div object itself and not its innerHTML.
window.onload = function() {
function mostrar() {
var elemento = document.getElementById("1")
document.write("<br>"+ elemento.innerHTML)
}
mostrar()
}
+ 3
! thanks ¡