Get only first class of an HTML element

Viewed 34417

I'm using the

event.target.className

to get the ClassName, but sometimes an element has multiple class names, how can I make it, so it only gives the first class name as outcome?

Oh, and please without jQuery.

2 Answers

If you'd want target the element to which the event handler has been attached use this

event.currentTarget.classList[0]

Related