Javascript examples for DOM:Element id
Get ID from element via tagname
<html> <head> <script> function getElements(){/* ww w . j a v a 2 s . co m*/ var x=document.getElementsByTagName("input"); console.log(x[0].id); } </script> </head> <body> <input id="hi" type="text" size="20"> <br> <input type="text" size="20"> <br> <input type="text" size="20"> <br> <br> <input type="button" onclick="getElements()" value="What is the ID for the first element?"> </body> </html>