Reputation: 498
How can i get all input that are checked in jQuery?
<div>
<input type="checkbox" checked="checked">sony </input>
<input type="checkbox">samsung </input>
<input type="checkbox"> Other</input>
</div>
Upvotes: 0
Views: 45
Reputation: 115212
You can use :checked
pseudo-selector
$(':checked')
console.log(
$(':checked').length
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type="checkbox" checked="checked">sony
<input type="checkbox">samsung
<input type="checkbox" checked>Other
</div>
FYI : There are various bugs in your code :
cheched
, the answer is based on checked
attribute.</input>
is invalid.Upvotes: 2
Reputation: 8101
You can try this:
<div>
<input type="checkbox" name="checkboxlist" checked="checked"> sony </input>
<input type="checkbox" name="checkboxlist"> samsung </input>
<input type="checkbox" name="checkboxlist" checked="checked"> Other</input>
</div>
jquery:
var checkValues = $('input[name=checkboxlist]:checked').map(function()
{
return $(this).val();
}).get(); // it will find list of all checked selectboxes
Upvotes: 1
Reputation: 347
Use Can Use This Code
$('input[type="checkbox"]:checked')
Upvotes: 2
Reputation: 18113
You can use:
$('input:checked')
More info: https://api.jquery.com/checked-selector/
Upvotes: 1