tags:

views:

522

answers:

2

The following code is NOT working, but how to correct it? Thx!

<html xmlns="http://www.w3.org/1999/xhtml"&gt; 
<head> 
<title></title> 
<link href="003.css" type="text/css" rel="stylesheet"/> 
<script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;

<script type="text/javascript">
  $(document).ready(function(){
     $("tr").removeClass();
     $("tr:gt(0)").click(function(){$(this).css("color","red")});
  });
</script>
</head>
<style type="text/css">
.highlight td {background: red;}
</style>
</head>
<body>
<table>
  <tr>
    <td>NAME</td>
    <td>AGE</td>
  </tr>
  <tr>
    <td>John Smith</td>
    <td>44</td>
  </tr>
  <tr>
    <td>Mary Green</td>
    <td>66</td>
  </tr>
  <tr>
    <td>Bob Black</td>
    <td>22</td>
  </tr>
</table>
</body>
</html>
A: 

You are not setting any of the <td> to class="highlight" so none of the backgrounds will be red.

Joe Philllips
That is NOT the reason it doesn't work. If you run this code, the row can be highlighted, but the problem is when a new row is highlighted, the old one is still there :(
Well then you clearly did not give us all of the relevant code (or a question)
Joe Philllips
+5  A: 

maybe try changing

$("tr:gt(0)").click(function(){$(this).css("color","red")});

into

$("tr:gt(0)").click(function() {
        $(".highlight").removeClass("highlight");
        $(this).addClass("highlight");
    });
cobbal
Thank you so much! it works.
If this answers your "question" then click the checkmark and mark it as the answer.
Joe Philllips
Sorry, first time user. where is the checkmark?
Never mind, I found it. Thank you!