Hi all,
I'm trying to get better at using Jquery and therefore would like feedback on ways to optimize my script below.
To briefly describe the functionality I have a "checkall" checkbox and a button for performing actions on the checked elements. If there's no elements checked, my button should be disabled and have the class disabled added aswell. If there's just one element checked the button should not be disabled, neither have the class disabled.
Thanks in advance
$(document).ready(function(){
$('#checkall').click(function () {
$(this).parents('.table_form:eq(0)').find(':checkbox').attr('checked', this.checked);
if($(this).parents('.table_form:eq(0)').find(':checkbox').is(':checked')) {
$("#delete_selected").attr("disabled");
$("#delete_selected").removeClass("disabled");
} else {
$("#delete_selected").removeAttr("disabled").addClass("disabled");
}
});
$("#blog_posts tbody :checkbox").click(checked_status);
});
function checked_status() {
var n = $("input:checked").length;
if(n > 0) {
$("#delete_selected").attr("disabled");
$("#delete_selected").removeClass("disabled");
} else {
$("#delete_selected").removeAttr("disabled").addClass("disabled");
}
}