Mi Viaje Full Stack en Java aprendiendo JavaScript

Guía práctica del DOM en JavaScript: conceptos, selección de nodos, manipulación de contenido y estilos, creación y eliminación de elementos y manejo de eventos con buenas prácticas.

3 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Día trece en JavaScript. Hoy continúo mi aventura My Java Full Stack Journey Learning in JavaScript y comparto lo que aprendí sobre el DOM, una base esencial para manipular interfaces web modernas y construir experiencias dinámicas y accesibles.

Qué es el DOM en JavaScript

DOM significa Modelo de Objetos del Documento. Es una interfaz de programación que representa una página HTML o XML como un árbol de nodos, donde cada etiqueta se convierte en un objeto que JavaScript puede leer, modificar, crear o eliminar en tiempo real.

Ejemplo de documento HTML mínimo interpretado como árbol DOM

Documento raiz html con dos secciones head y body. Dentro de head hay un title con el texto My Page. En body encontramos h1 con id heading y texto Hello World, un p con clase text y contenido This is a paragraph, y un button con id btn y texto Click Me. Cada uno de estos nodos es accesible y modificable desde JavaScript.

Acceso al DOM con JavaScript

Principales métodos de selección document.getElementById por id por ejemplo heading document.getElementsByClassName por clase por ejemplo text document.getElementsByTagName por etiqueta por ejemplo button document.querySelector y document.querySelectorAll con selectores CSS como #heading o .text

Modificar contenido Usa textContent para cambiar texto plano y innerHTML para inyectar HTML cuando necesitas etiquetas en el resultado.

Modificar estilos Accede a la propiedad style del elemento para aplicar cambios como color fondo tamaño de fuente márgenes y más. Ejemplo conceptual cambiar el color del h1 a azul y el tamaño del texto del párrafo a 20px.

Crear y eliminar elementos Con document.createElement puedes crear nodos como div p o li, asignarles contenido con textContent y añadirlos al documento con appendChild o prepend. Para eliminarlos, usa remove o removeChild según el caso.

Escuchar eventos addEventListener te permite reaccionar a interacciones del usuario como click input submit o keydown. Por ejemplo, al hacer click en el botón con id btn, mostrar una alerta o cambiar clases para animaciones.

Ejemplo guiado 1 Cambiar el texto del h1 con id heading para que muestre Bienvenido al DOM 2 Cambiar el color del párrafo con clase text a verde y aumentar su tamaño 3 Crear un nuevo párrafo con el texto Soy un nuevo párrafo y añadirlo al final del body 4 Registrar un evento click en el botón btn para mostrar un mensaje al usuario

Buenas prácticas Evita modificar innerHTML si no es necesario por seguridad y rendimiento Usa delegación de eventos cuando trabajes con muchos elementos dinámicos Separa estructura estilos y lógica para mantener el código escalable Prefiere classList para añadir o quitar clases en lugar de manipular style línea a línea

En Q2BSTUDIO desarrollamos productos digitales que aprovechan el DOM, componentes modernos y arquitecturas front y backend para crear aplicaciones a medida rápidas, accesibles y seguras. Si buscas un partner para construir o escalar tu plataforma, descubre nuestro enfoque de software a medida y aplicaciones a medida con stacks modernos y metodologías ágiles.

También impulsamos soluciones con inteligencia artificial, ia para empresas y agentes IA integrados en web y móvil para automatizar flujos de trabajo, enriquecer la experiencia de usuario y acelerar la toma de decisiones. Conoce más sobre nuestra oferta de inteligencia artificial.

Además, nuestro portafolio abarca ciberseguridad y pentesting, servicios cloud aws y azure, servicios inteligencia de negocio y power bi, y automatización de procesos para convertir datos y operaciones en ventajas competitivas. Todo ello con foco en rendimiento, escalabilidad y mantenimiento sostenible.

Palabras clave relevantes para tu proyecto y nuestro expertise aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, power bi, ia para empresas, agentes IA, automatización de procesos.

Sigue explorando el DOM y JavaScript, integra eventos, componentes reutilizables y patrones de arquitectura, y verás cómo tu código se vuelve más sólido y profesional. Feliz programación

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat