I have the following code where it manage to display the name of <DIV> tag in IE, but it display "undefine" in mozilla firefox browser. Anyone can help? thanx var elTags =document.getElementById("menuDiv").getElementsByTagName("div"); for (e=0;e<elTags.length;e++) { alert(elTags[e].name); }
Hi MMJ, thanks for yr reply. but what i want is to get the name of the div and not the nodeName. for example, i have a div tag with name "layer1" as below: <div name="layer1">This is Layer 1</div> In IE, i use var elTags =document.getElementById("menuDiv").getElementsByTagName("div"); for (e=0;e<elTags.length;e++) { alert(elTags[e].name); } it prompt me "layer1", but in mozilla firefox, it prompt me "undefine". alert(elTags[e].nodeName); return me "DIV" , but what i want is "layer1" Thanks for help.
Hi toonyew, Tag div has no xhtml valid "name" attribute that wrapped by javascript. The "name" attribute is only used in <input> <select> or <textarea> tags. So there are 2 solutions: 1. you change "name" attributes of sub divs to "id" and use elTags[e].id instead 2. Without changing anything, You use elTags[e].getAttribute("name")