How to use jquery Attr() to select only first attribute?
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");
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".
精彩评论