Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery selector for all checked checkboxes that are not disabled

how can I find all checkboxes, that are checked and not disabled?

like image 906
forkie Avatar asked Sep 10 '12 19:09

forkie


People also ask

How do you implement select all check boxes?

In Firefox (and maybe others?) : Hit CTRL+SHIFT+K to open the console, then paste : $("input:checkbox"). attr('checked', true) and hit Enter . All check-boxes on current page should now be checked. To un-check change True to False .

How do I enable and disable a checkbox?

Press the disable button and then the enable button. The checkbox doesn't get enabled. As the answers tell it is because the disabled attribute is a boolean attribute.

Can a checkbox be disabled?

The disabled property sets or returns whether a checkbox should be disabled, or not. A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in browsers. This property reflects the HTML disabled attribute.


1 Answers

Like so:

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

This finds fields that are inputs, with type checkbox, which are checked, and not disabled. If this does not work, you should use an attribute check:

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

Or, as @lonesomeday astutely pointed out, you can combine it into one selector:

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

I've put together a proof-of-concept in this fiddle.

like image 152
Cat Avatar answered Sep 17 '22 04:09

Cat