Manipulating DOM Elements

Seleccionar ElementosCrear Elementos

Once you select an element, you can change it in many ways: update its text or HTML content, modify attributes like src or href, add or remove classes, or apply styles directly.

These changes happen instantly in the browser – making pages dynamic and interactive.

Changing Text Content

Use textContent for plain text (safe, escapes HTML) or innerHTML for HTML markup.

Updating Attributes

Use setAttribute() or direct property access (like src, href, value).

Managing Classes with classList

classList provides methods: add, remove, toggle, contains.

Changing Inline Styles

Directly modify the style property (camelCase for properties like backgroundColor).

Quick Quiz

Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.

✨ Pregunta a Lara — tu compañera de estudio con IA

Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.


Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.

Sigue Tu Progreso 🚀

Aprende más fácilmente siguiendo tu progreso completamente gratis.