25.74. Document.getElementById( ): find an element with the specified unique IDDOM Level 2 Core:25.74.1. SynopsisElement getElementById(String elementId); 25.74.1.1. Arguments
25.74.1.2. ReturnsThe Element node that represents the document element with the specified id attribute or null if no such element is found. 25.74.2. DescriptionThis 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
|