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

143
Views
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
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!