Entry
How do I use the method parent?
How do I use the method parent?
Apr 16th, 2005 23:01
Martin Honnen,
The method parent takes no argument and returns the common parent of all
XML objects in this XMLList if all those objects have the same parent,
otherwise undefined is returned.
Here are some examples:
// common parent
var gods = <gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>;
var godList = gods.god;
alert(godList.parent().name()); // shows 'gods'
// if all XML objects have parent as null they do have the same
// parent value thus calling parent on the XMLList returns null
var godList = <>
<god>Kibo</god>
<god>Xibo</god>
</>;
alert(godList.parent()); // shows 'null'
// different parents for the XML objects in the XMLList
var html = <html>
<head>
<title>Kibology</title>
</head>
<body>
<h1>Kibology</h1>
</body>
</html>;
var xmlList = html..*;
alert(xmlList.parent()); // shows 'undefined'