Section 25.74. Document.getElementById( ): find an element with the specified unique ID


25.74. Document.getElementById( ): find an element with the specified unique ID

DOM Level 2 Core:

25.74.1. Synopsis

 Element getElementById(String elementId); 

25.74.1.1. Arguments

elementId

The value of the id attribute of the desired element.

25.74.1.2. Returns

The Element node that represents the document element with the specified id attribute or null if no such element is found.

25.74.2. Description

This method searches the document for an Element node with an id attribute whose value is elementId and returns that Element. If no such Element is found, it returns null. The value of the id attribute is intended to be unique within a document, and if this method finds more than one Element with the specified elementId, it may return one at random, or it may return null. This is an important and commonly used method because it provides a simple way to obtain the Element object that represents a specific document element. Note that the name of this method ends with "Id", not with "ID"; be careful not to misspell it.

In HTML documents, this method searches for an element based on the value of its id attribute. Use HTMLDocument.getElementsByName( ) to search for HTML elements based on the value of their name attributes.

In XML documents, this method performs its search using any attribute whose type is id, regardless of what the name of that attribute is. If XML attribute types are not known (because, for example, the XML parser ignored or could not locate the document's DTD), this method always returns null. In client-side JavaScript, this method is not usually useful with XML documents. In fact, getElementById( ) was originally defined as a member of the HTMLDocument interface but was then moved to the Document interface in DOM Level 2.

25.74.3. See Also

Document.getElementsByTagName( )
Element.getElementsByTagName( )
HTMLDocument.getElementsByName( )



JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net