Javascript getElementById Method Example

Updated on     Kisan Patel

To get the html element by their id attribute, we need to use HTML DOM getElementById() Method.

<script language="javascript" type="text/javascript">
function TestFunction() {
<label id="divText">Hello World!</label>
<input type="button" id="btnTest" onclick="TestFunction()" value="Click me" />

In the above function, getElementById finds a div element with id “divText” and shows its inner HTML content as an alert.

See the Pen eNXPjz by Kisan (@pka246) on CodePen.


Leave a Reply