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.
In order to silence the typescript warning you can cast EventTarget
to Element
and then use className
property
(event.target as Element).className
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With