Jump to content

how to get childNodes[x] to look at only nonwhitepace nodes.


arianhojat

Recommended Posts

i was kinda used to Flash actionscript where i can set whitespace to be avoided so.
childNodes[0]
and
childNodes[1]
return 1st 2 nodes...

However i realized Javascript returns whitespace nodes with the results so childNodes[0] and childNodes[1] actually dont return what i want...
so it returns 'visually'...
whitespace[0]
<childNodes[1] />
whitespace[2]
<childNodes[3] />
whitespace[4]

Is there anyway, or soem function i can use that just returns the next node, avoiding everything but regular element nodes?

i guess the best i could think of is a function like so...

[code]function getChildNodes( parentElement, Index)//index of node to look for inside parentElement
{
var actualI=0; //the current Element Node index being looked at
for(var i=0; i<parentElement.childNodes; i++) //looping through all nodes
{
  var currentNode = parentElement.childNodes[i];
  if(currentNode.nodeType==1) //if current node is an Element
  {
      if(Index==actualI) //if currentNode is index looking for
      return currentNode;
      else //next Element in the loop which is found, will have the actual index value of actualI
      actualI++;
  }

}
}[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.