JavaScript > Dealing with HTML Controls

Finding element using ID in JavaScript

How to find a HTML element using on it’s ID in JavaScript?

To find the html controls by their id attribute, we can follow this approach.

        function TestFunction() {

    <label id="lblText">0</label>
    <input type="button" id="btnTest" onclick="TestFunction()" value="Click me" />

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


 Views: 763 | Post Order: 57

Write for us