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?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

How do I use the method prependChild?
How do I use the method prependChild?

Apr 12th, 2005 00:40
Martin Honnen,


The method prepend child takes one argument, the value to prepend,
inserts that value as the first child of the XML object and returns the
XML object.
Note that when the value passed in is an XMLList then each element in
the list is prepended.
Here are some examples:
  var gods = <gods>
    <god>Xibo</god>
  </gods>;
  gods.prependChild(<god>Kibo</god>);
  alert(gods);
  /* shows
  '<gods>
     <god>Kibo</god>
     <god>Xibo</god>
   </gods>'
  */
  // string value passed in prepended as text node:
  gods.prependChild("Kibology for all.");
  alert(gods);
  /* shows
  '<gods>
     Kibology for all.
     <god>Kibo</god>
     <god>Xibo</god>
   </gods>'
  */
  // XMLList value passed in prepends each element in the list:
  gods.prependChild(<><god>Maho</god><god>Jaffo</god></>);
  alert(gods);
  /* shows
  '<gods>
     <god>Maho</god>
     <god>Jaffo</god>
     Kibology for all.
     <god>Kibo</god>
     <god>Xibo</god>
   </gods>'
  */