Archive for jQuery

Javascript / jQuery get first class name of element

Need to get the first class name of an element? Simple! Imagine having a link with 3 class names

<a id="myelement" href="http://google.com" class="class1 class2 class3">Go to google</a>


$('a#myelement').attr('class').split(' ')[0]

Will result in: class1