want to get over a confusion with jquery
-
<html>
<head>
<style>
.odd
{
background-color: #ffc; /* pale yellow for odd rows */
}
.even
{
background-color: #cef; /* pale blue for even rows */
}
.highlight
{
font-weight:bold; color: #f00;
}
.table-heading{font-weight:bold; color: #f00;}
</style>
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script>
$(document).parent().ready(function() {
$('th').addClass('table-heading');
$('tr:even:not([th])').addClass('even');
$('tr:odd:not([th])').addClass('odd');
$('td:contains("Henry")').parent().find('td').not(':contains("Henry")') .addClass('highlight');
});
</script>
</head>
<body>
<table>
<tr>
<th>Title</th>
<th>Category</th>
<th>year<th>
</tr>
<tr>
<td>As You Like It</td>
<td>Comedy</td>
<td>1988</td>
</tr>
<tr>
<td>All's Well that Ends Well</td>
<td>Comedy</td>
<td>ccc</td>
</tr>
<tr>
<td>Hamlet</td>
<td>Tragedy</td>
<td>ckc</td>
</tr>
<tr>
<td>Macbeth</td>
<td>Tragedy</td>
<td>cwdc</td>
</tr>
<tr>
<td>Romeo and Juliet</td>
<td>Tragedy</td>
<td>wd</td>
</tr>
<tr>
<td>Henry IV, Part I</td>
<td>History</td>
<td>jcb</td>
</tr>
<tr>
<td>Henry V</td>
<td>History</td>
<td>bcdgc</td>
</tr>
</table>
</body>
</html>
hey the above code just run perfect but i want to ask that this line from above code
$('td:contains("Henry")').parent().find('td').not(':contains("Henry")') .addClass('highlight');
according to me should work exactly the same when i change it to this
$(':contains("Henry")').parent().find('td').not(':contains("Henry")') .addClass('highlight');
because there is oly two <td> that canatins the henry text with in them that two tds are in same <tr> so even when i use the second one they would produce the same parent....but they are not doing the same thing as the previous line did....confused over this i am..