I'd like to add a nice light yellow highlight to the table row that the user is interacting with. They click on an 'A' link with an 'onclick' function call that uses jquery to do stuff (not important). The onclick is in an 'A' tag and in a table cell 'TD'.
Here is the table cell:
<td>
<a href="javascript:void(0);"
onclick="deleteSchedule('Ajax/Admin_Delete_Schedule.cfm?SID=12345');"
title="Delete User"><img src="images/Delete_x16_.png" border="0"></a>
</td>
How do I get the reference for the table row and then set the background color? Do I need to give each table row a unique ID?
Since the answers are so detailed and excelelnt, I'll add this: I'd like to do this within my function but I'm not sure how to do it with 'this'. Thanks!! and OMG! stackoverflow is the greatest!!!
I could not get the below closest or parent examples to work but I did get this to work:
$(".rowClick").on("click", function() {
$(this).closest("tr").css('backgroundColor', '#FFFF99');
});
and of course I added the class 'rowClick' to the 'A' tag. The problem now is when the user clicks on another row the result is two rows highlighted. Any suggestions to remove the highlight from the previously selected row. (I'm guessing to change the background color on all the table rows then set the one clicked on.) - Thanks Again!