Trying to understand differences between Firefox DOM and IE DOM structure/ syntax

Posted on 2008-11-05
Last Modified: 2013-11-19

I am still new to manipulating the DOM and am doing a few exercises to build up my knowledge. I was trying out some tutorials I found online but I seem to be running into disprepancies from what the tutorial said I should be seeing when viewing in Firefox. Instead of seeing an alert message posting "DIV", I get an alert message displaying "#text". When I view it in IE, it displays the DIV pop up just fine. Is this because the DOM syntax in firefox is different than the one in IE? What areas should I watch out for when I'm working with it between the two? Thanks


<body bgcolor="white"> 

<div id="a" style="font-family: Arial; color: black;  

background: white">Wassup?</div> 

<script language="JavaScript"> 

var obj = document.childNodes[0].childNodes[1].childNodes[0]; 

alert(obj.nodeName); = "red"; 




Open in new window

Question by:MikeZ_LaFrance
    LVL 4

    Accepted Solution

    try obj.tagName. actually there are a lot of differences you must watch out between IE and Firefox. It is hard to say especially what you should watch out. try and see.
    LVL 42

    Assisted Solution

    by:David S.
    IE doesn't include white-space-only text nodes in the childNodes[] nodeList (it's a lot like an array) or any other way to refer to a child or sibling of an element.

    You can use this function instead of accessing childNodes[] directly:

    function getChildNode(elm,num,type) { // 2nd and 3rd args are optional
      num=num||0;type=type||1; // by Kravvitz of
      var i=-1,n=elm.childNodes,l=n.length,k=-1;
      while(++i<l) if(n[i].nodeType==type && ++k==num) return n[i];
      return null;

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    CFFILE upload help 98 88
    Cannot submit form in ASP.NET MVC 3 48
    SharePoint JSOM error 7 32
    Javascript - getdate 5 36
    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now