Entendiendo el DOM
¿Para qué aprender JavaScript?
¿Qué es DOM y Window Object?
Explorando Nodos del DOM
Seleccionando y Accesando a Elementos del DOM
Consultando el DOM con getElementById y querySelector
Navegación efectiva entre nodos
Manipulando Elementos del DOM
Modificando atributos y propiedades
Modificando texto en HTML
Modificando estilos en HTML
Modificando la visibilidad de elementos HTML
Creación de elementos con HTML Strings e insertAdjacentElement()
Agregando elementos con innerHTML e insertAdjacentHTML()
Creación de elementos con createElement()
Remover elementos con remove() y removeChild()
Clonación y reemplazo de elementos con cloneNode y replaceChild
Manipulando Eventos en el DOM
Entendiendo eventos y tipos: Burbuja, Captura y Propagación
Agregar y eliminar escuchadores de eventos o Event Listeners
El objeto evento o eventObject
Manejo de entradas de formulario y validación
Delegación de eventos y prevención de comportamiento predeterminado
Creando un Administrador de Tareas
Añadir tareas desde un formulario
Eliminar y editar tareas del DOM
Almacenamiento y carga de datos en localStorage
Eliminar y editar tareas del almacenamiento local
Inspeccionando y solucionando errores en el código
Personalizando la interfaz del administrador de tareas
Aún hay más por aprender
Asincronía en JavaScript
¿Cómo funciona el JavaScript Engine?
You don't have access to this class
Keep learning! Join and start boosting your career
Selecting Document Object Model (DOM) elements is a fundamental skill in web development. It allows you to transform static pages into interactive and dynamic experiences. In this article, we will explore how to efficiently manipulate such elements with JavaScript.
Modifying a single DOM element is a key process for customizing details, such as the user greeting. If we want to change the title of a page on load, we must first identify the specific element. Suppose we have a title with the ID app-title
.
In this case, we can make use of the getElementById
method to access that element, then modify it via JavaScript. The code would look as follows:
let titulo = document.getElementById("app-title");titulo.textContent = "Welcome, Diego";
Another alternative is to use querySelector
, which also selects single elements, adding the flexibility to select by tags or attributes:
let titulo = document.querySelector("#app-title");titulo.textContent = "Welcome, Diego";
Selecting multiple elements is common when dealing with lists or groups of components, such as menu items or table elements. We can use getElementsByClassName
to get a collection of all the elements that share the same class.
let items = document.getElementsByClassName("menu-items");
Likewise, using getElementsByTagName
, you can access all items with a certain tag, such as paragraphs(<p>
):
let paragraphs = document.getElementsByTagName("p");
If you prefer querySelectorAll
, this method will return a NodeList of items that correspond to a specific selector, such as a class:
let menuItems = document.querySelectorAll(".menu-items");
Query speed in the DOM has a major impact on the performance of web applications, especially when handling large volumes of data or elements. Methods such as getElementById
and getElementsBy...
are generally faster than querySelector
and querySelectorAll.
However, the latter allow more flexibility in queries and are current trends in the industry.
In conclusion, when choosing how to select DOM elements, consider your performance needs and the specifics of your project. With practice, you will find that mastering these techniques will enrich your development skills and allow you to deliver exceptional user experiences. Continue to explore and train yourself on this exciting path of web development!
Contributions 19
Questions 1
Este es un párrafo.
` `Este es un párrafo.\
\` del DOM. Este método devuelve una colección que incluye no solo los elementos visibles, sino también propiedades adicionales, como el nodo padre, atributos y texto de los nodos. Esto es parte de la estructura del DOM, que incluye tanto elementos visuales como nodos de texto y comentarios. Es importante entender que el DOM es un modelo de objetos que representa toda la página, no solo lo que se ve.
Want to see more contributions, questions and answers from the community?