XML DOM namedItem() methode
Definitie en gebruik
De methode namedItem() haalt een knoop of element op uit de verzameling met een specifieke naam.
Het gedrag van deze methode verschilt afhankelijk van het type document:
-
Als het document een HTML-document is, zal deze methode eerst zoeken naar knopen met een id-eigenschap die overeenkomt met de gegeven naam, als er geen overeenkomstige id-eigenschap wordt gevonden, dan wordt gezocht naar knopen met een name-eigenschap die overeenkomt met de gegeven naam.
When querying an HTML document, this method is not case-sensitive.
-
If the document is an XHTML document, this method only queries nodes with an id attribute that matches the given name.
When querying an HTML document, this method is case-sensitive.
Syntax:
htmlcollectionObject.namedItem(name)
Parameter | Description |
---|---|
name | The name of the node or element to retrieve. |
Return value
Returns an element or node with the specified id or name attribute. If there is no such node in the HTMLCollection, it returns null.
Description
In JavaScript, treat HTMLCollection as an associative array and use array syntax to place name in [] to find elements will be easier.
Example
var c = document.forms; //This is an HTMLCollection object var address = c.namedItem("address"); //Find <form name="address"> var payment = c["payment"]; //Simpler syntax: find <form name="payment"> var login = c.login; //This is also valid: find <form name="login">