Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!