Reputation: 6762
I am trying to check and uncheck checkbox by clicking on text next to it. Here is the example in which i am trying to click on item name and checkbox should be selected. I think toggle should fit here but I am unable to make it work.
$("#checkall").change(function () {
$(this).closest("table").find(".checkbox").attr("checked", this.checked).change();
});
$(".checkbox").change(function() {
$(this).closest('tr').toggleClass("highlight", this.checked);
});
Upvotes: 0
Views: 609
Reputation: 388316
I think you are targeting the fileName, if so then try
$("#checkall").change(function () {
$(this).closest("table").find(".checkbox").prop("checked", this.checked).change();
});
$(".checkbox").change(function () {
$(this).closest('tr').toggleClass("highlight", this.checked);
});
$('.filename').click(function () {
$(this).closest('tr').find('input').prop('checked', function (i, c) {
return !c;
}).change()
})
Demo: Fiddle
Upvotes: 2