Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all checked checkboxes with similar id's using Jquery?

This might be the easiest question of the day.

i have a groups of checkboxes with similar id's (all starting with someid_ like someid_0,someid_1..)

i want to get all checked checkboxes.

I have tried $('input:checkbox[id^="someid_"]:checked') but it's not working?

like image 901
Jishnu A P Avatar asked Feb 04 '11 05:02

Jishnu A P


1 Answers

this code is working check demo

http://jsfiddle.net/csTpG/

Markup

<input type="checkbox" id="someid_1" checked/>
<input type="checkbox" id="someid_2" checked/>
<input type="checkbox" id="someid_3" checked/>
<input type="checkbox" id="someid_4"/>

jQuery

var n = $('input:checkbox[id^="someid_"]:checked').length;
alert(n); // count of checked checkboxes

$('input:checkbox[id^="someid_"]:checked').each(function(){
    alert($(this).attr("id"));});
like image 115
Harish Avatar answered Oct 17 '22 04:10

Harish