[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2008-11-05
Medium Priority
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]; 
obj.style.color = "red"; 

Open in new window

Question by:MikeZ_LaFrance

Accepted Solution

obareey earned 1000 total points
ID: 22890041
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 43

Assisted Solution

by:David S.
David S. earned 1000 total points
ID: 22890330
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 DynamicSiteSolutions.com
  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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

834 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