I’m using jQuery 1.6.1 and the attr() method, It’s working fine on all browsers except IE7.
In the console, It highlights the setAttribute function in jQuery JS and says: Not Implemented
I think IE7 doesn’t support that, so i tried to work around it:
if(Object.prototype.hasOwnProperty('setAttribute')){
$(e).attr(key, value);
}else{
e[key] = value;
}
It’s still telling me:
Object doesn’t support this action
What’s the solution for this?
jQuery handles all odd cases well, there’s usually no need to work around anything. Also note what Šime Vidas said,
setAttributeisn’t defined onObject.prototypeand even if it would be, in IE8 and lower HTML elements don’t inherit fromObjectso the feature detection wouldn’t probably work as expected.What’s the value of
keyvariable? Consider usingprop()if more appropriate, oraddClass()if you work with classes.