ZVON > References > DOM2 Reference

getElementById (method )

Owning interface and usage:  
Document.getElementById(elementId)

Member of these other interfaces:  
none

Description:  
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID.

Parameters:  
DOMString elementId  -  The unique id value for an element.

Returns:  
Element -  The matching element.

Exceptions:  
none

Note:  
The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.


Example:
Text in the first DIV.
Some text in the second DIV.
Some text and element in the third DIV.
We can try another elements. It will be much more interesting.
Text in the last DIV.
Source:
   <div id="doc">
     <div>
       Text in the first DIV.
     </div>
     <div id="DDD" class="secondClass">
       Some text in the second DIV.
     </div>
     <div class="thirdClass">
       Some text and <span id="SSS">element</span> in the third DIV.
     </div>
     <div class="fourthClass">
       We can try <i>another elements</i>.
       It will be much more <b>interesting</b>.
     </div>
     <div>
       Text in the last DIV.
     </div>
   </div>
     
JavaScript:
  var output1 = document.getElementById('doc').nodeName;
  var output2 = document.getElementById('SSS').nodeName;
Output:
desired your browser
output1: DIV
output2: SPAN