JQuery - get first class only from element
The item is as follows:
<li class="blah active"> ... </li> jQuery.attr('class') will return both classes. How can I get only 1st class ('blah' in this case) with jQuery?
+50
Alex Jul 08 '10 at 13:17 2010-07-08 13:17
source share2 answers
You need to split that into an array:
console.log(jQuery('selector').attr('class').split(' ')[0]); +110
Sarfraz Jul 08 '10 at 13:20 2010-07-08 13:20
source share var first = jQuery.attr('class').split(" ")[0]; +5
galambalazs Jul 08 '10 at 13:19 2010-07-08 13:19
source share