Get paragraph text using JavaScript
The getElementById() method is used to return the element that has the ID attribute with the specified value. This is one of the most common methods in the HTML DOM and It is used almost every time we want to manipulate an element on our document.
This method returns a null value, if no elements with the specified ID exists.
Note : The ID should be unique within a page. However, if more than one element with the specified ID exists, it returns the last element in the javascript code, Let's see.
Let's see the simple instance :
➤ Example :
<p id="element">www.coderwebsite.com</p>
<script>
var get_text = document.getElementById("element").innerHTML;
document.write(get_text);
</script>
Output :
www.coderwebsite.com
Comments