Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Accessing DOM with JS

I am taking up JS on my own. This endeavor exposes me to various ways of achieving the same thing in JS. Particularly, I wondering about the correctness of the following ways of working with the DOM.

I have a simple html page

<body>
        <h1 class="red">I am red</h1>
        <h2 class="blue">I am blue</h2>
        <h3 class="yellow">I am yellow</h3>
        <script src="app.js"></script>
</body>

Here, I am trying to change the color of the html elements with a click event

document.body.addEventListener("click", function (event) {
    if (!(event.target === document.body)) {
        event.target.style.color = event.target.classList;
    }
});



Array.from(document.body.children).forEach((child) => {
    child.addEventListener("click", function () {
        this.style.color = this.classList;
    });
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda