开发者

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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜