faqts : Computers : Programming : Languages : JavaScript : XML : E4X (ECMAScript for XML) : XML objects

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

How do I use the method childIndex?
How do I use the method childIndex?

Apr 9th, 2005 03:36
Martin Honnen,


The method childIndex takes no argument and returns a number value: if
the XML object the method is called on has no parent then the special
number value NaN (not a number) is returned, otherwise the ordinal
position the object has in the context of its parent is returned:
  XML.ignoreComments = false;
  var gods = <gods>
    <!-- Kibology for all. -->
    <god>Kibo</god>
    <!-- All for Kibology. -->
    <god>Xibo</god>
  </gods>;
  alert(gods.childIndex());  // shows 'NaN'
  var god1 = gods.god[1];
  alert(god1.childIndex()); // shows 3
  var comment1 = gods.comments()[1];
  alert(comment1.childIndex()); // shows 2