-1
<a class="ab ac ad">HOME</a>

I need the second class attribute, something like this:

$("a").click(function(){
var a = $(this).attr("class").eq(1);
alert (a);
});

Any idea ?

qadenza
  • 8,611
  • 18
  • 61
  • 108

2 Answers2

3

You get a string, so you can just split it:

var a = $(this).attr("class").split(' ')[1];
Guffa
  • 666,277
  • 106
  • 705
  • 986
  • 2
    Why the downvote? If you don't explain what it is that you think is wrong, it can't improve the answer. – Guffa Jun 16 '14 at 08:52
1

You can split by space using:

echo $(this).attr("class").split(' ')[1];
Milind Anantwar
  • 79,642
  • 23
  • 92
  • 120