the code is below [HIGHLIGHT="JavaScript"]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <object id="1e"><embed name="donny" /><embed name="aaaa" /></object> <script type="text/javascript"> <!-- function getNode() { var obj = document.getElementsByTagName('object'); for(i in obj) { alert(obj[0].childNodes[0].name); } } getNode(); //--> </script> </BODY> </HTML> the above code works in firefox but not in IE can some one please help. I am writing code for a flash file. it has to get the embed tags in the object. it works in firefox but not in IE it gives empty.
i think the problem here is that in IE, the object element is implemented ... differently. The problem here is that anything that's between the tags <object> and </object> is seen as a 'fallback': so as the DOM loads, it does not care to see what child elements the object has or initialise them; the object loaded ok, so thats fine. in this instance, obj[0].childNodes.length will be 0... now, to prove this, replace the object tag with div or span or whatever - it starts working straight away! another proof: var embeds = document.getElementsByTagName("embed"); alert("embeds: ", embeds.length); // alerts 0! Code (markup): basically, these embeds are not a part of the dom or the parent object. it is recorded as innerHTML though, so you can copy the content into another element and apply the checks there... var getNode = function() { var obj = document.getElementsByTagName('object'); var i = obj.length; while (i--) { var newdiv = document.createElement("div"); newdiv.innerHTML = obj[i].innerHTML; var elements = newdiv.childNodes; var e = elements.length; while(e--) { alert(elements[e].getAttribute("name")); } } } // end getNode getNode(); Code (markup): even though you'd get all childnodes this way, don't know to what avail -- you cannot reference the real embeds via document.getElementbyId or any way I can think of - then again, I am not that hot on vanilla javascript. another thing. do not name an ID of an element to anything that starts with a numeric character.