- 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.
- If two or more elements with the same id exist, getElementById() returns the first.
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to change the text in this paragraph.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
document.getElementById("demo").innerHTML = "Hello World!";
}
</script>
</body>
</html>
0 comments
Post a Comment