+ 1

¿Why this outputs "null"

any info will help https://code.sololearn.com/WKrsa0wEg7LL/?ref=app

29th Oct 2017, 4:28 AM
Aldo
Aldo - avatar
2 ответов
+ 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() }
29th Oct 2017, 4:57 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
! thanks ¡
29th Oct 2017, 5:31 AM
Aldo
Aldo - avatar