2

I have more class in 1 div:

 <div class=" class1 class2 class3> content </div>

how can i get 1 class: ex class 2 in this div. thanks!

Xmindz
  • 1,282
  • 13
  • 34
Huỳnh Tú
  • 115
  • 1
  • 7
  • [get-class-list-for-element-with-jquery](http://stackoverflow.com/questions/1227286/get-class-list-for-element-with-jquery) – Leo Silence May 29 '15 at 04:56
  • Many browsers will already support the classList property, e.g. `$('div').prop('classList')[1];` – Ja͢ck May 29 '15 at 05:26

2 Answers2

2

You can use split like this:

alert($('#yourDivID').attr('class').split(' ')[1]);

To get all classes, you can do this instead:

var classes = $('#yourDivID').attr('class').split(' ');

for(var i=0; i<classes.length; i++){
  alert(classes[i]);
}
Rasel
  • 5,488
  • 3
  • 30
  • 39
1

Try this

$('#divId').attr('class').split(" ")[1]
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83