Prashant Prashant - 1 month ago 4
jQuery Question

How to select a row in table using jquery?

I have created a table in my application, I want to select (change background color) whole row on click of a checkbox, same as gmail is doing, When we click checkbox in gmail, the whole row becomes yellow.

<td><input type="checkbox" name="chk" id="chk" /></td>
<td>My Name</td>
<td>Description of the job</td>

Please tell me how to do the same in jquery?

$(function() {
  $("#chk").click(function() {

Create a CSS class (called "diffColor" above) and add the background color that way, something like:

<style type="text/css">
tr.diffColor td { background-color: yellow; }

Don't set CSS attributes directly. Use classes where possible.