HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Get the element with the specified id
The getElementById()
method returns an element with a specified value.
The getElementById()
method returns null
if the element does not exist.
The getElementById()
method is one of the most common methods in the HTML DOM.
It is used almost every time you want to read or edit an HTML element.
Any id should be unique, but:
If two or more elements with the same id exist, getElementById()
returns the first.
The getElementsByTagName() Method
Parameter | Description |
id | Required. The id value of an element. |
Type | Description |
Object | The element with the specified id.null if the element does not exist. |
CSS Tutorial: CSS Syntax
CSS Reference: CSS #id Selector
HTML DOM Reference: HTML DOM id Property
HTML DOM Reference: HTML DOM Style Object
document.getElementById()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |