I have a table with multiple rows. Each row has a check button. How do i highlight the row (apply style I suppose) when the checkbox is selected?
3 Answers
$(":checkbox").change(function() {
$(this).closest("tr").toggleClass("highlight", this.checked);
});
See toggleClass() and closest()
3 Comments
Winfield Trail
Looks like they both add the class. Typo?
karim79
@Kerin - it was. I revised my answer, made it more concise using
.toggleClass.Winfield Trail
Right on. Incidentally, you just taught me about .closest() - golly, me and jQuery are getting married someday.