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

285
Views
Can't retrieve key inside the return value of event.composedPath()

Question: The return value of event.composedPath() contains property keys that are difficult to retrieve. I've tried everything I know and can't get to them.

In the simplified example below I used Object.getOwnPropertyNames() to return an array of all properties on the object. the first alert box shows the values, 0,1,2,3,4,5,length. The second alert box is blank.

<div style="width: 200px; height: 200px; background-color: yellow">
    <a data-target="0" href="">click me</a>
</div>

<script>
    document.querySelector('[data-target]').addEventListener( 'click', event => {
        const elementsInPath = event.composedPath();
        alert(Object.getOwnPropertyNames(elementsInPath));
        alert(Object.getOwnPropertyNames(elementsInPath[0]));
    });
</script>

Output: In Devtools I put a watch on elementsInPath. The output below is what shows up. I'm trying to return the strings, "a" "div" "body" "html" "document" "window". As shown above they aren't listed with getOwnPropertyNames(). I've tried every normal targeting method to retrieve these and I can't get to them. Ultimately what I'm trying to do is determine if an anchor 'a' is in the path so I can use event.preventDefault() to end the event.

  • elementsInPath: Array(6)
  • 0: a
  • 1: div
  • 2: body
  • 3: html
  • 4: document
  • 5: Window
  • length: 6
  • [[Prototype]]: Array(0)
about 4 years ago · Juan Pablo Isaza
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!