En esta parte del tutorial veremos como acceder a los elementos del DOM HTML con el método getElementById(id) que nos permitirá acceder a ellos a través del identificador dado en el atributo id.
Código del ejemplo del capítulo ...
<!DOCTYPE HTML> <html> <head> <script> window.onload = function() { var box_1 = document.getElementById("box-1"); //alert(box_1.innerHTML); box_1.innerHTML = "<strong>Cambiando el contenido con innerHTML</strong>"; var box_2 = document.getElementById("box-2"); box_2.style.color = "orange"; box_2.style.backgroundColor = "black"; box_2.style.fontSize = "25px"; var campo = document.getElementById("campo"); //alert(campo.value); campo.value = "Value cambiado"; } </script> </head> <body> <div id="box-1">Hola mundo 1</div> <div id="box-2">Hola mundo 2</div> <br><br> Campo de texto: <input type="text" id="campo" value="Valor"> </body> </html>
No hay comentarios:
Publicar un comentario