Skip to content Skip to sidebar Skip to footer

Get First Class Of Element

So let's I have a div with multiple classes like this:
In the javascript I only want the first class, like $(document.body).on('click','.s',f

Solution 1:

Try this:

$('.s').click(function()
{ 
  var firstClass = $(this).attr('class').split(" ")[0];
});

Solution 2:

Try This:

var firstClass = this.className.split(" ")[0];

No need to wrap it back into a jQuery element and incur the performance cost.

Post a Comment for "Get First Class Of Element"