HTML DOM Document GetElementById() Method - W3Schools
Maybe your like
Example
Get the element with the specified id:
document.getElementById("demo"); Try it Yourself »Get the element and change its color:
const myElement = document.getElementById("demo"); myElement.style.color = "red"; Try it Yourself »Or just change its color:
document.getElementById("demo").style.color = "red"; Try it Yourself »Description
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.
Note
Any id should be unique, but:
If two or more elements with the same id exist, getElementById() returns the first.
See Also:
The getElementsByTagName() Method
The getElementsByClassName() Method
The querySelector() Method
The querySelectorAll() Method
Syntax
document.getElementById(elementID)Parameters
| Parameter | Description |
| id | Required.The id value of an element. |
Return Value
| Type | Description |
| Object | The element with the specified id. null if the element does not exist. |
Related Pages:
CSS Tutorial: CSS Syntax
CSS Reference: CSS #id Selector
HTML DOM Reference: HTML DOM id Property
HTML DOM Reference: HTML DOM Style Object
Browser Support
document.getElementById() is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera | IE |
| Yes | Yes | Yes | Yes | Yes | 9-11 |
Tag » What Is Getelementbyid In Javascript
-
How "getElementByID" Works In JavaScript? - Tutorialspoint
-
tElementById() - Web APIs | MDN
-
JavaScript - GetElementbyId 사용법 - 기억보다 기록을
-
What Is The GetElementByID Method() In JavaScript?
-
What Is tElementById() In JavaScript?
-
JavaScript - tElementById() Method - Javatpoint
-
How GetElementByID Works In JavaScript ? - GeeksforGeeks
-
JavaScript GetElementById() - Selecting An Element By Id
-
Javascript GetElementById - W3schools.blog
-
JavaScript GetElementById() - EduCBA
-
tElementById In Javascript - Lesson 1 - YouTube
-
[JavaScript] tElementById - 블로그 - 네이버
-
[JavaScript] JS GetElementById() 이용한 아이디 요소 객체 선택
-
[Javascript] tElementById() - 하늘과 나의 IT 이야기