jQuery - if two classes - get the first one
Example:
Here we have <p class="tab1 current"></p>
How can I get only the first class?
var GetFirstClass = $('p').attr('class').filter(':first');
??
Any help开发者_开发问答 much appreciated.
Use JavaScript's split
function:
$('p').attr('class').split(' ')[0]
Demo
$('p').attr('class').split(' ')[0]
You can split
the string based on the space.
$('<div class="a b"/>').attr('class').split(' ')[0]
精彩评论