How to remove a CSS class from all same level tabl

2019-09-08 11:01发布

问题:

$('table tbody tr').click(function () {
            // how to remove clickedRow class from all same level rows?
            $(this).addClass('clickedRow');
        });

When a row is selected, I'd like to remove the clickedRow css class from all other rows of the same table and only add it to the currently selected row.

there are more than table in my page so each click should do as above only in the context of the same table.

How would that be possible?

Thanks,

回答1:

You can use this:

$('table tbody tr').click(function () {
    $(this).siblings().removeClass('clickedRow');
}

it will remove your css class from all sibling rows



回答2:

$(this).siblings('.clickedRow').removeClass('clickedRow');