I have an anchor as follows:
<a href="#" class="Menu">Text</a>
How can I get the CSS Class of this anchor using JQuery?
So in this case I would get "Menu".
I am able to add and remove CSS classes but I can't find a way to get the CSS classes of an element. What can I do ?
Use the native property :
$(selectorOrElement).get(0).className
Note that it's often answered to use attr('class')
. Not only is there no gain in using a complex function instead of the native DOM property but it's also, quite naturally, much slower. See jsperf
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