Object.prototype.hasAttr = function(attr) {
if(this.attr) {
var _attr = this.attr(attr);
} else {
var _attr = this.getAttribute(attr);
}
return (typeof _attr !== "undefined" && _attr !== false && _attr !== null);
};
I came a crossed this while writing my own function to do the same thing... I though I'd share in case someone else stumbles here. I added null because getAttribute() will return null if the attribute does not exist.
This method will allow you to check jQuery objects and regular javascript objects.