[thelist] DOM: accessing properties of "children" array SOLVED

Tom Dell'Aringa pixelmech at yahoo.com
Mon Aug 12 17:00:01 CDT 2002


In short, my problem was getting to the properties of each child in
the children array, using the DOM. The answer is using the attributes
collection.

You can get a list of all of one elements children like this:

var nodeObj = document.getElementById(rowID);
group = nodeObj.children;

To get at each individual child:

for (i = 0; i < group.length; i++)
{
   var attrMax = group[i].attributes.length;  //size of ALL
attributes
   var TDnodeObj = group[i];  //each child in group

for(var j = 0; j < attrMax; j++)
{
   if(TDnodeObj.attributes.item(j).nodeName == "class")
   {
      if(TDnodeObj.attributes.item(j).nodeValue == "rowTD")
      {
         TDnodeObj.style.color = "#003366";
      }
   }
}

You step through each attribute until you find the desired one (I
wanted the class). If its the class you want (I wanted rowTD) then,
do some desired actions to it. I changed the color.

My next question is how to make this cross-browser. It doesn't do
squiddly in NN6.2 or Mozilla 1, or Opera. Seems odd, I would figure
that at least SOMETHING would happen, since this is DOM code...

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



More information about the thelist mailing list