TOC PREV NEXT INDEX

domref



getElementById


Returns the element whose ID is specified.

Syntax

element = document.getElementById(id);
 

Parameters

element is an object.

id is a string representing the unique id of the element being sought.

Example

// for <p id="p1" class="reggy" align="right">text</p>
 
first_p = document.getElementById("p1");
 
a_list = first_p.attributes;
 

Notes

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.

Specification

getElementById
 


Netscape Communications
http://developer.netscape.com
TOC PREV NEXT INDEX