Parece que este código está funcionando bien. Pruébalo antes de responder:
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p>In this example, x, y, and z are variables.</p> <p id="demo"></p> <script> let x = 7; let y = 45; let z = x + y; demo.innerHTML = "The value of z is: " + z;//please note this line </script> </body> </html>¿Significa esto que puedo reemplazar document.getElementById("id"). con solo DNI???
Está funcionando, pero se considera heredado e inseguro.
Parece que sí, y también funciona para elementos anidados... Sin embargo, me pregunto si funciona en un archivo js diferente importado del html.
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p>In this example, x, y, and z are variables.</p> <p id="demo1"> <p id="demo2"></p> </p> <p id="demo"></p> <script> let x = 7; let y = 45; let z = x + y; demo.innerHTML = "The value of z is: " + z;//please note this line demo2.innerHTML = "The value of z is: " + z;//please note this line console.log(demo); </script> </body> </html>