15 January, 2009

jQuery hide unchecked Check Boxes

In my scenario a user can select people to add to a list (using checkboxes). The update is done via jQuery $post so there is no refresh. In order to make it seem more fluent I need to hide all the people that are not checked making it seem as though there was a full update. *a full update happens when the user refreshes the page.

So the solution: use jQuery to hide checkboxes that are not checked.


var divId = "yourDivID";

$("#"+divId+" input:checkbox").not(":checked").each(function(){
$(this).next().hide();
$(this).hide();
});


the text next to the checkbox is inside a span tag. This allows it to be recognised correctly when using .next()

No comments: