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

284
Vistas
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
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