Site Navigation

Friday, August 24, 2007

bug 217 - getAttribute doesn't always work in IE

Issue: #217
Affects: IE5, IE5.5, IE6, IE7, IE8 Beta 1, IE8 Beta2, IE8 PR1
Fixed In: IE8 RC 1

Certain attributes can not be retrieved properly in IE. The first example, is the "for" attribute, which is used by <label> tags to link to input fields.

Example:
<script type="text/javascript">
var myLabel = document.getElementById( 'test' );
alert( 'myLabel is for: ' + myLabel.getAttribute( 'for' ) );
</script>

There is a workaround for this (see below)


Known Workarounds: Some.

Example Workaround Code:
<script type="text/javascript">
var myLabel = document.getElementById( 'test' );
alert( 'myLabel is for: ' + myLabel.attributes['for'].nodeValue );
</script>



Related Issues: None.