Returns the element whose ID is specified.
element = document.getElementById(id);
element is an object.
id is a string representing the unique id of the element being sought.
// for <p id="p1" class="reggy" align="right">text</p>
first_p = document.getElementById("p1");
a_list = first_p.attributes;
getElementById is an absolute mainstay of the DOM. One of the most important notions in DOM programming is that elements be identified uniquely so that they can be grabbed and manipulated.
If there is no element with the given ID, this function returns NULL. Note also that 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.
getElementById was introduced in DOM Level 2.