jQuery Form How to - Retrieve value from hidden input element








Question

We would like to know how to retrieve value from hidden input element.

Answer


<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head><!--from  w  w  w  .  j  a v a 2s  .co m-->
<body>
  <input type="hidden" id="theid1" value="11" />
  <input type="hidden" id="theid2" value="22" />
  <input type="hidden" id="theid3" value="33" />
  <script>
$('input[id^="theid"]').each(function () {
   console.log($(this).val());
});
</script>
</body>
</html>

The code above is rendered as follows: