I have a series of checkboxes, and everything works except their default behavior has been altered unintentionally so I can no longer check them which is odd since the reason I was using this bit of jquery was to highlight the li around them when they got checked in the first place.
Any ideas?
//Tag cloud
$(".tag-cloud li").toggle(
function () {
//$(this).filter(":checkbox").attr('checked', 'true');
$(this).addClass("selected");
return;
//return $(this).filter(":checkbox").attr("checked", true);
},
function () {
//$(this).filter(":checkbox").attr('checked', 'false');
$(this).removeClass("selected");
return;
//$("#sortable").submit();
}
);
You can simplify it overall and hopefully eliminate the odd behavior by using a simple
.click()event handler, like this:This has the benefit of working regardless of what state it was initially in, where as
.toggle()will be off for pre-checked boxes.If you want the
<li>itself clickable, we need to be sure not to get in a loop or reverse the toggle when clicking the actual checkbox itself (if it’s exposed), like this: