teslariu

DOM Html

Jul 11th, 2022
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. //codigo de index.html
  3.  
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7.     <meta charset="UTF-8">
  8.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  9.     <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
  10.     <title>Probando JavaScript</title>
  11. </head>
  12. <body>
  13.     <h1 id="titulo">Hola a todos</h1>
  14.     <script src="js/codigo.js"></script>
  15. </body>
  16. </html>
  17.  
  18. */
  19.  
  20.  
  21. // accedemos al HTML DOM
  22. var enunciado = document.getElementById('titulo')
  23.  
  24. // muestra el tipo de etiqueta
  25. alert(enunciado);
  26.  
  27. // muestra el contenido de la etiqueta
  28. alert(enunciado.innerHTML);
  29.  
  30. // modificamos u obtenemos el contenido de un elemento
  31. var enunciado = document.querySelector('h1')
  32. enunciado.innerHTML = "Nuevo contenido"
Advertisement
Add Comment
Please, Sign In to add comment