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

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

Try this

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