I need that when i check a checkbox i apply different background color to HTML table rows according to and ID of a user in database using jquery, and then i uncheck the checkbox go to previous state.
For the record i am not asking for code i am asking for concept.
I need that when i check a checkbox i apply different background color to
Share
You want to use a selector that matches the table rows, get the id of the user from the row and choose the color, then use the
cssfunction to set thebackground-color. You can use thedatamethod to store the previous color. When your checkbox is unchecked, simply get the previous color using data, and restore it.If the id of the user isn’t included in the row or relatable to the row somehow, then you’ll need to change the table and add it, otherwise it isn’t possible.
Here’s a little code to get you started — this is the “check” part.
EDIT: Based on your comment, I think CSS classes may be a better solution for you — just assign the group name as the class. Then in your CSS have different CSS selectors for
.groupXand.groupX.active,.groupYand.groupY.active, etc. Then all you need to do is add/remove the active class from the rows on checkbox toggle. I don’t know if the “active” class name is the most semantically appropriate, but it’s convenient for the example.