Will this test to check if an element has an attribute work? Here is my code:

hasAttr = new function(tag, attrName) {
    return (tag.attrName)
}


Will this code work? I can't test it now because I cannot acces jsfiddle and jsbin but Down For Everyone or Just Me? says something else.


jsFiddle Down For Everyone or Just Me
jsBin Down For Everyone or Just Me


Example usage:

JavaScript:

alert(hasAttr("div", "id"))


HTML:

&lt;div id="header"&gt;&lt;/div&gt;


Expected:

(In alert box)
    true
                OK


Can someone test it for me?

If it doesn't work, how should I code it?

I want hasAttr to return true or false.

I will be open to code optimization, cleaner code etc.

Thanks in advance!
To check if an HTML element has an attribute, you should use hasAttribute. If you have to support IE6 and IE7, check its existence using [name].

Given that, the implementation of hasAttr would be something like this:

hasAttr = function(tag, attrName) {
    return tag.hasAttribute ? tag.hasAttribute(attrName)
                            : tag[attrName] !== undefined;
}