开发者

What is the preferred method of retrieving class names with jQuery?

开发者 https://www.devze.com 2023-01-11 00:00 出处:网络
So far, I\'m using $(this).attr(\'class\'); But I worry about compatibility because I know some browsers do some weird things wi开发者_JAVA百科th class and id attributes. Seems like a great place f

So far, I'm using

$(this).attr('class');

But I worry about compatibility because I know some browsers do some weird things wi开发者_JAVA百科th class and id attributes. Seems like a great place for jQuery to implement its own method, but I can't find it in the documentation.

Isn't there a bug somewhere that has className and id acting on the same objects? This may only apply to IE setting values, or maybe I'm just misremembering.

As meder pointed out, I was thinking of id and name, not id and class.


.attr('class') would work out because internally it uses className

0

精彩评论

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