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
Event not Bubbling to Parent Element from Child Element

I read the article on https://javascript.info/bubbling-and-capturing about Bubbling.

According to the article, the following event on the article tag with id="article" should have bubbled to the <p id="para"></p>, inside which article is nested.

    let para = document.getElementById("para");
    let article = document.getElementById("article");

    /*
    article.addEventListener("click", () => {
        console.log("I'm an article tag!");
    });
    */
    para.addEventListener("click", () => {
        console.log("I'm a p tag!");
    });
        <p id="para">
            <article id="article">Click Me!</article>
        </p>

However, absolutely, nothing happens. The Event listener on article works just fine(when not commented out). Why?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your HTML is invalid. An <article> can't be a child of a <p> - check out the rendered HTML:

console.log(document.body.innerHTML);
<p id="para">
  <article id="article">Click Me!</article>
</p>

As a result, the browser ends the <p id="para"> when the <article> tag begins - so they're no longer parent and child, but siblings.

(The <p> tag can only contain phrasing content, which the <article> tag is not)

Make sure your HTML passes validation first.

If you used something else valid - like a <span> - it'd work:

let para = document.getElementById("para");
let article = document.querySelector("span");

/*
article.addEventListener("click", () => {
    console.log("I'm an article tag!");
});
*/
para.addEventListener("click", () => {
  console.log("I'm a p tag!");
});
<p id="para">
  <span id="article">Click Me!</span>
</p>

about 4 years ago · Juan Pablo Isaza Denunciar
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