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

143
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

Try this

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