Reputation:
I'm currently using jQuery and would like some help on iterating through all "checked" checkboxes and remove a class (called "new_message") of the parent table row.
I've got a basic concept, but I can't quite figure the entire thing out.
Here is what I am currently using:
$("#unread_button").click(function (event) {
event.preventDefault;
$(":checkbox:checked").each(
function()
{
if (this.checked)
{
var divs = $.makeArray($(this).parents("tr").attr("id"));
}
$(divs).each(
function(int)
{
$(this).removeClass("new_message");
}
);
});
});
Eventually, this will be updating a database as well, so if the code can be tailored to accomodate both, that'd be great.
Any guidance is much appreciated!
Upvotes: 6
Views: 14426
Reputation: 4521
I think this will work:
$('input:checkbox:checked').parents('tr').removeClass('new_message');
Or if it's only the direct TR parent you want to match, then this:
$('input:checkbox:checked').closest('tr').removeClass('new_message');
jQuery does all the looping for you so you should have to have all the each()es.
Once you use the ':checked' selector, you should have to recheck if the item is checked. This should limit your selector results to only checked items.
Upvotes: 6
Reputation: 22238
$("input:checked").each(function() {
$(this).removeClass("new_message");
}
will remove the relevant class from the checkboxes themselves, so
$(this).parent....
should work depending on what your HTML looks like
Upvotes: 4