i have li that has class name more then one ,
so i want to get first class name
For Example
<li class="class1 smfont">1<li>
<li class="class2 smfont">2<li>
<li class="class3 smfont">3<li>
<li class="class5 smfont">5<li>
i want to get the class name only class1, class2, class3….
by jquery
i use
var $filteredData = $data.find('li[class=' + $filterType + ']');
but not work
An easy way to do it is:
.attr("class")gets the class names as a space-separated string, so the next step is to split that based on the spaces and just select the first element in the resulting array. You might want to trim it before splitting first if you don’t control the HTML you’re working with.You can see a working example at http://jsfiddle.net/wXuFt/