I’m working on a project in ASP and I’m not used to Javascript or Jquery
I found some code that if I click on a row, it will change the color.
I now want to change the display to normal when I click on a row and then hide it if I click on any other row.
What I have so far
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>INFO</th>
</tr>
</thead>
<tbody>
<tr onclick="changeMe(this);">
<td>INFO</td>
<tr class="versionRow" style ="display:none">
<td>INFO</td>
</tr>
</tr>
</tbody>
</table>
And my script for changing the color.
<script>
var whosChanged = null;
function changeMe(el) {
el.style.backgroundColor = "#00FF00";
el.style.color = "#000000";
if (whosChanged != null) {
whosChanged.style.backgroundColor = ""
whosChanged.style.color = ""
}
whosChanged = el;
}
</script>
I just want to be able to display the row with the class versionRow when I click on it.
Any ideas or suggestions? Thank you.
Here’s one approach:
This does rely on well-formed HTML, though: as noted in my comment to your question a
tris only a valid child of atable,thead,tbodyandtfootelements. It is not a valid child of anothertr. You could nest atableinside of atd, but there should be no elements inside of atrexcept fortdandth. That said, the following HTML will allow the above script(s) to work:JS Fiddle demo.
Note that I’ve taken out the
onclickevent-handlers, to separate the behaviour from the mark-up, and, hopefully, make things more maintainable in future. I’ve also moved the (invalid) nestedtrfrom its parent and added it as a sibling.