Blu
Blu

Reputation: 4056

Identify Checked checkboxes in jquery

I create Multiple checkBox under the one div with data-role="controlgroup" Now i want to check that after click on specific button which check boxes are checked using JQuery so what is the best way for do it

Upvotes: 0

Views: 110

Answers (4)

Blu
Blu

Reputation: 4056

Using this you can get all of your checked ckeckboxes

code from here

var selected = new Array();
$('#checkboxes input:checked').each(function() {
    selected.push($(this).attr('name'));
});

Upvotes: 0

Anil kumar
Anil kumar

Reputation: 4177

try like this.

$("div[data-role='controlgroup'] input:checkbox :checked")

Upvotes: 1

Rituraj ratan
Rituraj ratan

Reputation: 10378

use :checked

$("div[data-role='controlgroup'] :checkbox :checked")// by this you get all checked checkbox

Upvotes: 1

theftprevention
theftprevention

Reputation: 5213

Try something like this...

if ($("div[data-role='controlgroup'] input[type='checkbox']").first().prop("checked")) {
    // ...
}

That's a pretty hefty selector, and it'll only fetch the first <input type="checkbox" /> that's inside a <div data-role="controlgroup">. You should tweak it to make it more specific to your project.

In short, jQuery's .prop() method with "checked" as the argument will return a Boolean true or false depending on whether a checkbox is checked.

Upvotes: 1

Related Questions