JavaScript: Count inputfields in a Div

Thom picture Thom · May 1, 2014 · Viewed 8.2k times · Source

I have a <div id="inputform"> and in that div there are multiple <input type="text"> . How can I count the number of <input> fields?

Answer

Brian Warshaw picture Brian Warshaw · May 1, 2014
var inputFormDiv = document.getElementById('inputForm');
alert(inputFormDiv.getElementsByTagName('input').length);