How to loop through all the elements returned from getElementsByTagName [duplicate]

You need to convert the nodelist to array with this: <html> <head> </head> <body> <input type=”text” value=”” /> <input type=”text” value=”” /> <script> function ShowResults(value, index, ar) { alert(index); } var input = document.getElementsByTagName(“input”); var inputList = Array.prototype.slice.call(input); alert(inputList.length); inputList.forEach(ShowResults); </script> </body> </html> or use for loop. for(let i = 0;i < input.length; i++) { … Read more