Prev Demo
JavaScript
>
Finding HTML Element By Name Attribute
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Finding HTML elements by name</h1> <script> function TestFunction() { document.getElementsByTagName("label")[0].innerHTML = 50; } </script> <label id="lblText">0</label> <label id="Label1">0</label> <input type="button" id="btnTest" onclick="TestFunction()" value="Click me" /> <p><strong>Note:</strong> In the script code we have given name as 'label', so that it will find the elements of label in the HTML code.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output