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

141
Views
Get Class Name of Element from MouseEvent Target

I need the class name of an EventTarget, which I'm getting like this:

<div class="orig-post" (mousemove)="onMouseMove($event)"></div>

onMouseMove(event: MouseEvent): void {
    this.target = event.target
    console.log(this.target) // Outputs the element the mouse is currently over
}

I'd like to be able to assign a variable to the class name of the element that is the target. If I were using something like getSelection() I could just do something like selection.anchorNode.parentElement.className. Is there a way to do this in pure javascript? I'm using Angular 2 and would like to avoid jQuery entirely.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

In order to silence the typescript warning you can cast EventTarget to Element and then use className property

(event.target as Element).className
over 4 years ago · Santiago Trujillo Report

0

<div class="orig-post" (mousemove)="onMouseMove($event.target.value)"></div>

onMouseMove(event: MouseEvent): void {
    this.target = event.target
    console.log(this.target) // Outputs the element the mouse is currently over
}

over 4 years ago · Santiago Trujillo Report

0

Try this

event.target.classList
over 4 years ago · Santiago Trujillo Report
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!