Entry
How do I use the method setChildren?
How do I use the method setChildren?
Apr 12th, 2005 01:43
Martin Honnen,
The method setChildren takes one argument, the replacement value, and
replaces all children of the XML object with this value. The method
returns the XML object it is called on.
The replacement value can be an XML object or an XMLList object where in
the latter case each element in the XMLList becomes a new child of the
XML object the method is called on.
Here are some examples:
var gods = <gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>;
gods.setChildren(<god>Maho</god>);
alert(gods);
/* shows
'<gods>
<god>Maho</god>
</gods>'
*/
gods.setChildren(<><god>Kibo</god><god>Xibo</god></>);
alert(gods);
/* shows
'<gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>'
*/