I am trying to change the color of the selected row from a table on a onmousedown
event and reset
all others (or keep them the same) . Only one row can be red
at a time while all others are green
.
What I have tried:
function HighLight(id) {
var rows = $('#tbl > tbody > tr').each(function(elem) {
elem.style.background = 'green';
})
var tr = document.getElementById(id);
tr.style.background = 'red';
}
<table id="tbl">
<tr id="tr1" style="background-color:aquamarine" onmousedown="Highlight(e)">
<td>
v1
</td>
</tr>
<tr id="tr2" style="background-color:aquamarine" onmousedown="Highlight(e)">
<td>
v2
</td>
</tr>
<tr id="tr3" style="background-color:aquamarine" onmousedown="Highlight(e)">
<td>
v3
</td>
</tr>
</table>
Ideally I would like to store the old
selected row so that I won't reset all others at each new selection, but in case I can't reset all would do it.
P.S I need to make due with the id
that i am provided.I am using interop
so the id is coming from the exterior. All my tr
have that method injected in them.