Check if checkbox checked jquery

Show hide input field on the basis of checkbox hidden or visible

by sunil puvvada

HTML

<input name="checkbox" value="1" type="checkbox" />
<input name="checkbox" value="2" type="checkbox" />
<input name="checkbox" value="3" type="checkbox" />
<input name="checkbox" value="4" type="checkbox" />
<button id="button" type="button">button</button>

JavaScript

$(document).ready(function () {

  var tmp = [];
  
  $("input[name='checkbox']").change(function() {
  var checked = $(this).val();
    if ($(this).is(':checked')) {
      tmp.push(checked);
    }else{
    tmp.splice($.inArray(checked, tmp),1);
    }
  });
 
  $('#button').on('click', function () {
		alert(tmp);
  });
  
});