I am trying to trigger an event when I click on a td with class toggle. When I click on a td with class toggle, I want to show all the next tr with class hidethis.
But I cant seem to trigger an event on the td. Here's what I have got so far.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> </script>
<script type="text/javascript">
$(document).ready(function () {
$(' td .toggle ').on('click',function(ev){
$(this).closest('tr').nextAll('tr .hidethis').show();
});
});
</script>
</head>
<body>
<table border="1">
<tr >
<td class="toggle">First Toggle</td>
</tr>
<tr class = "hidethis" style="display:none">
<td>Value 1</td>
<td>Value 2 </td>
<td>Value 3</td>
</tr>
<tr >
<td class="toggle">Second Toggle</td>
</tr>
<tr class = "hidethis" style="display:none">
<td>Value 4</td>
<td>Value 5 </td>
<td>Value 6</td>
</tr>
</table>
</body>
</html>
The problem is when I click on the td with class toggle the event is not firing.
Please help me. May be I am not seeing something obvious.
Thanks in advance.
$('td.toggle ')remove the space.