Hi All,
I'm trying to write a piece of jQuery code where, if all checkboxes are "unchecked", then all li tags have the class "disabled."
But, if one checkbox (any checkbox) is checked, then all [li] tags lose the class "disabled".
Many thanks!
Hi All,
I'm trying to write a piece of jQuery code where, if all checkboxes are "unchecked", then all li tags have the class "disabled."
But, if one checkbox (any checkbox) is checked, then all [li] tags lose the class "disabled".
Many thanks!
$(':checkbox').click(function () {
$('li').toggleClass('disabled', !$(':checkbox:checked').length);
});
$(':checkbox')
.click(
function()
{
$('li').toggleClass('disabled', $(':checkbox :checked').length <= 0));
}
);
EDIT: Thanks Ken for pointing out toggleClass method.
Slight modification of Phillipe Leybaert's, which will include any dynamically added checkboxes:
$('input[type=checkbox]').live('click', function () {
if ($('input[type=checkbox]:checked').length)
{
$('li').addClass('disabled');
}
else
{
$('li').removeClass('disabled');
}
});
$(':checkbox') .click( function() { $('li').toggleClass('disabled', $(':checkbox :checked').length <= 0)); } );