Loop though all input boxes and clear them

dom, html, javascript

Solution

Try this code:

​$('input').val('');

It's looping over all `input` elements and it's setting their value to the empty string. Here is a demo: http://jsfiddle.net/maqVn/1/

And of course if you don't have jQuery:

var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i += 1) {
    inputs[i].value = '';
}​​​​

Since I prefer the functional style, you can use:

Array.prototype.slice.call(
  document.getElementsByTagName('input'))
  .forEach(function (el) {
    el.value = '';
});

Problem

How can I, using javascript, loop through all input boxes on a page and clear the data inside of them (making them all blank)?

Original source