I’m trying to show hide table rows by assigning a number id to the class attribute of the tr element
I have it coded so that the first instance of this number id is shown while the rest are hidden. Clicking the first instance should reveal the rest of the rows with the same id.
This is the code I have so far, however it fails to reveal the rest of the rows:
The following code is in the document.ready function
var ids = ["1","2","3","4","5","6","7","8","9","10"];
var i;
for (i = 0; i < ids.length; i++) {
$("." + ids[i]).hide()
$("." + ids[i] + ":first").show()
$("." + ids[i] + ":first").click(function () {
if( $("." + ids[i] + ":last").css('display') == 'none') {
$("." + ids[i]).show()
} else {
$("." + ids[i]).hide()
$("." + ids[i] + ":first").show()
}
});
}
The html is just
<tr class="<%= @current_id %>">
<td>test data</td>
<td>test data</td>
</tr>
you have many errors:
then
then close all methods with
";":to
also the class
.1or.2etc .. are not valid you should replace that with.1-rowthen , actually you are selecting all the
trbut not thetdelements, you should do somenthing like: