Site Navigation

Tuesday, September 25, 2007

bug 204 - getElementsByTagName doesn't always work in IE

Issue: #204
Affects: (IE6 unconfirmed), IE7, IE8 Beta 1, IE8 Beta 2, IE8 PR1, IE8 RC1

{element}.getElementsByTagName('*');

Should return all child elements, regardless of nodeName, however it fails under the following scenarios.

Example:

<object id="myObj">
<param name="foo" value="37"/>
<param name="bar" value="75"/>
<param name="baz" value="99"/>
</object>
<script type="text/javascript">
var objTag = document.getElementById('myObj');
alert(objTag.getElementsByTagName('*').length);
</script>


The alert, should indicate a length of 3 child elements, but in IE7 it returns 0 (zero). This bug only occurs with an object element, and child param elements.


Known Workarounds: One. You will need to query specifically for 'param' tag elements.

Example Workaround Code:

<object id="myObj">
<param name="foo" value="37"/>
<param name="bar" value="75"/>
<param name="baz" value="99"/>
</object>
<script type="text/javascript">
var objTag = document.getElementById('myObj');
alert(objTag.getElementsByTagName('param').length);
</script>



Related Issues: None.