Reputation: 4107
Here is my code.
function switchbox(showall, maincls) {
$(showall).change(function() {
if ($(this).is(":checked")) {
$(maincls).each(function(i) {
$(this).attr('disabled', true);
});
} else {
$(maincls).each(function(i) {
$(this).attr('disabled', false);
});
}
});
}
switchbox('.show-all-tags, .tags');
switchbox('.show-all-cats, .categories');
It works if i didn't use variables inside the function. It should disable all checkboxes of that class when the show-all-X is checked and vice versa. and i tried it without the variables showall, maincls it works. What I am doing wrong here please?
Thank you.
Upvotes: 2
Views: 85
Reputation: 5957
maincls isn't being defined, maybe you meant:
switchbox('.show-all-tags', '.tags');
switchbox('.show-all-cats', '.categories');
Upvotes: 7