开发者

jquery .attr() not working in IE7. Any work around to get the class of the element?

开发者 https://www.devze.com 2023-03-19 09:51 出处:网络
I am having this code to check if the element has the certain class: var p3div = $(\"#portlet1 #showhide\");

I am having this code to check if the element has the certain class:

var p3div = $("#portlet1 #showhide");
            if (p3div.attr('class').indexOf('ui-icon-plusthick') > 0) {
                //do something here.
            }

However in IE7 .attr() is not supported and this code will throw an error. Is there any other way to get the class of an element by not using the attr(开发者_如何学C) method?

Thanks,


if($('#showhide').hasClass('ui-icon-plusthick')){
     // do something
}
  1. No need to use anything other than jQuery's native hasClass() function.
  2. No need to select elements which have an id with the descendants way, like #portlet #showhide, this will be way slower.
0

精彩评论

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