tags:

views:

84

answers:

1

Hello,

I have a div as follows:

<DIV CLASS="variable productPopup"></DIV>

When assigning it to a var, how do I only select variable? Please note that variable changes, so it needs to select the first item, not literally the words "variable"

var ID = $(this).attr("class");
+5  A: 

To get the first class mentioned, you can split the value by spaces:

var firstClass = $(this).attr("class").split(" ")[0];

So if the class attribute was "foo Bar", you'd get "foo".

Jonathan Sampson