Faqts : Business : Programming : Shopping For You : 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 hasOwnProperty?
How do I use the method hasOwnProperty?

Apr 10th, 2005 03:10
Shopping Snooper, Casino Vendor Directory, 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'