Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda