JavaScript getElementById() Method
You are Here:
JavaScript getElementById() Method
The getElementById()
method returns the element whose id attribute matches the specified string.
Note: Element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="point"></p>
<script>
var txt = "<strong> Hello there! </strong>";
document.getElementById("point").innerHTML = txt;
</script>
</body>
</html>
Syntax
document.getElementById(elementID)
Parameter Values
Value | Type | Explanation |
---|---|---|
elementID | Required | The id name of the elements you want to get. |
More Examples
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="point">I like green</p>
<script>
var x = document.getElementById("point");
x.style.color = "green";
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.