jQuery Form How to - Loop though all input boxes and clear them








Question

We would like to know how to loop though all input boxes and clear them.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  ww w.  j  a  va  2s  .co m-->
    $('input').each(function () {
        $(this).val('');
    });
});
</script>
</head>
<body>
  <input type="text" value="text" />
  <input type="text" value="text" />
  <input type="text" value="text" />
</body>
</html>

The code above is rendered as follows: