Availability
DOM Level 1 HTML
Synopsis
Node namedItem(String name);
Arguments
name
The name of the element to be returned.
Returns
An element with the specified name, or
null if no elements in the HTMLCollection have
that name.
Description
This method finds and returns an element from the HTMLCollection that
has the specified name. If any element has an id
attribute whose value is the specified name, that element is
returned. If no such element is found, an element whose
name attribute has the specified value is
returned. If no such element exists, namedItem( )
returns null.
Note that any HTML element may be given an id
attribute, but only certain HTML elements -- such as forms, form
elements, images, and anchors -- may have a
name attribute.
In JavaScript, it is easier to treat the HTMLCollection as an
associative array and to specify name
between square brackets using array notation.
Example
var forms = document.forms; // An HTMLCollection of forms
var address = forms.namedItem("address"); // Finds <form name="address">
var payment = forms["payment"] // Simpler syntax: finds <form name="payment">
var login = forms.login;// Also works: finds <form name="login">
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.