Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through all checkboxes on the page?

How do I can iterate through all checkboxes on the page with JQuery?

I.e. I have those checkboxes above...

<div>
<input checked="checked" type="checkbox" name="option_1" id="checkbox_1" value="1" />35 MM                  
<input checked="checked" type="checkbox" name="option_2" id="checkbox_2" value="2" />  DIGITAL                    
<input type="checkbox" name="option_3" id="checkbox_3" value="3" /> 3D DIGITAL
</div>

Have I use

 $('input[id^="checkbox_"]').each(function() {

 });

Is it correct? Thank you!

like image 275
Friend Avatar asked Nov 16 '25 20:11

Friend


1 Answers

$("input[type='checkbox']").each(function(){
  var name = $(this).attr('name'); // grab name of original
  var value = $(this).attr('value'); // grab value of original
  var ischecked = $(this).is(":checked"); //check if checked
});
like image 81
themhz Avatar answered Nov 19 '25 09:11

themhz