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
}
- No need to use anything other than jQuery's native
hasClass()
function. - No need to select elements which have an id with the descendants way, like
#portlet #showhide
, this will be way slower.
精彩评论