views:

24

answers:

2

Hi,

I have a table row elements:

... <tr index="1000" class="class1 classHighlightRed"> ...
... <tr index="1000" class="class1 classHighlightYellow"> ...

I would like to check the value of the second class against some constants.

E.g.

    If (2nd class == "classHighlightRed") Then
    {
      doSomeWork;    
     }

At the moment I'm achieving this through the following hack:

var 2ndClass = $(this).attr("class").substring(7);

Is there a nicer way to achieve this?

+3  A: 
var 2ndClass = $(this).attr("class").split(' ')[1];
redsquare
+1 redsquare :-)
ILMV
Spot on! :) THank you!
vikp
+3  A: 

I believe you can use the hasClass method for this?

if($(this).hasClass('classHighlightRed')) Then 
{
doWork;
}

More info here

HTH

DannyLane
Thank you, this is slightly better options since I'm not a great fan of string manipulations.
vikp