How can I get only first grade? var GetFirstCla...">

JQuery - if two classes - get the first

Example:

Here we have <p class="tab1 current"></p>

How can I get only first grade?

var GetFirstClass = $('p').attr('class').filter(':first'); ??

Any help is greatly appreciated.

+4
source share
4 answers

Use JavaScript split :

 $('p').attr('class').split(' ')[0] 

Demo

+13
source
 $('p').attr('class').split(' ')[0] 
+6
source

You can split string based on a space.

+2
source
 $('<div class="ab"/>').attr('class').split(' ')[0] 
0
source

All Articles