-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
  • 9,025
  • 18
  • 73
  • 126

2 Answers2

3

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

var a = $(this).attr("class").split(' ')[1];
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • 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
  • 81,290
  • 25
  • 94
  • 125