peace_love
peace_love

Reputation: 6471

How can I disable a checkbox with a specific class?

Hello I am disabling all checkboxes which are not checked.

$(":checkbox:not(:checked)").prop('disabled', true)

My problem is that I do not know how to select only the checkboxes with the class checkbox. I tried to do it like this:

$(".checkbox:checkbox:not(:checked)").prop('disabled', true)

Upvotes: 0

Views: 111

Answers (2)

Keval Bhatt
Keval Bhatt

Reputation: 6322

See this examle http://jsfiddle.net/uwsy2xuv/1/

<input type="checkbox" class="checkbox">
<input type="checkbox">
<input type="checkbox" class="checkbox" checked>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox" class="checkbox">

jquery

console.log($("input[type='checkbox']"))  //selector for all checkbox.
console.log($("input[type='checkbox'].checkbox")) //selector for all checkbox which has class checkbox.



$("input[type='checkbox'].checkbox:not(:checked)").prop('disabled', true)
OR
$("input:checkbox.checkbox:not(:checked)").prop('disabled', true)

Upvotes: 2

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

Use this way:

$("input.checkbox:checkbox:not(:checked)")

Upvotes: 4

Related Questions