/

HTML / CSS / JavaScript Tutorial

JavaScript Document own method: getElementById()

[this page | pdf | back links]

The getElementById() method (when applied to the document object of the JavaScript DOM) returns the element with the specified id attribute (if it exists).

 

It has the following syntax with the following parameters. It returns an element object, representing the element with the specified id as its id attribute or null if no such element exists.

 

document.getElementById(id)

 

Parameter

Required / Optional

Description

id

Required

String specifying the value of the id attribute of the element you want to obtain

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile