Entry
How do I use the method hasOwnProperty?
How do I use the method hasOwnProperty?
Apr 10th, 2005 03:10
Martin Honnen,
The method hasOwnProperty takes one argument, the property name, and
returns true if the XML object the method is called on has a property of
that name and false otherwise.
Note that child elements and attributes are treated as properties of an
XML object:
var gods = <gods type="usenet">
<god>Kibo</god>
<god>Xibo</god>
</gods>;
// 'element properties'
alert(gods.hasOwnProperty('god')); // shows 'true'
alert(gods.hasOwnProperty('devil')); // shows 'false'
// 'attribute properties'
alert(gods.hasOwnProperty('@type')); // shows 'true'
alert(gods.hasOwnProperty('@date')); // shows 'false'