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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.