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

155
Vistas
Why do I get an error when accessing parentElement on an EventType object?

The code below sets the background of an element when it gets focus:

document.addEventListener(
        'focusin',
        (event) => {
          if (event.target !== null && event.target.parentElement.classList.contains('note')) {
            event.target.parentElement.style.backgroundColor = "#E6FBFF"
          }
        })

It works on my browser (Chrome).

The IDE and build process raise an error:

ERROR in src/components/Note.vue:146:98
TS2339: Property 'parentElement' does not exist on type 'EventTarget'.
    144 |           }
    145 |         })
  > 146 |       document.addEventListener('focusout', (event) => {if (event.target !== null) {event.target.parentElement.style.backgroundColor = "white"}})
        |                                                                                                  ^^^^^^^^^^^^^
    147 |     })
    148 |
    149 |     const setFocus = (event) => {

I d not understand the error (besides of course its nature), I was under the impression that event.target would give me a handler to the element the event (of type EventTarget) happened on.

How should I address this error?

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