getAttribute("for") is always null in Internet Explorer

The getAttribute() method will return "null" in Internet Explorer when trying to get the for attribute of a label element.

Solution: use attributes['for'].nodeValue.

Test page Workaround is included
Reported by: Laurent Muchacho.

Explorer 5-6 Windows, Explorer 7 | Reported on 22 March 2007.

This site is no longer maintained. I’m sorry, but it’s just too much work for too little return. You can continue to browse old bug reports, though.

Search reports by browser:

Atom RSS


(Add your own)

1 Posted by Simon on 22 March 2007 | Permalink

But the work around doesn't work for safari! So I guess making a function to get the attribute and test for the result before passing it back.

var Element = {
getAttribute: function(element, value){
return element.getAttribute(value);
return element. attributes[value];

Obviously a better version can be written (this is just an example written in this text box)...

2 Posted by Wiktor on 22 March 2007 | Permalink

AFAIK getAttribute("htmlFor") works for IE.

3 Posted by Tino Zijdel on 23 March 2007 | Permalink

It is well-known that IE wants to have the javascript-alternative when using get/setAttribute. That includes 'for' (htmlFor) and 'class' (className).

If you need a crossbrowser solution for this than just use the 'old' method: element.htmlFor = 'foo'