<table>
<tr>
<td align="center" class="topmenu"><a href="../cases/showProject.asp?ID=<%=ID%>" onclick="if(gv_changeHaveBeenMade){return window.confirm('<%= TR("Page change but not saved. Continue?") %>')}"><img src="../Grafik/newMenuAnalyse.png" alt="" border="0"></a><a href="../cases/showProject.asp?ID=<%=ID%>" onclick="if(gv_changeHaveBeenMade){return window.confirm('<%= TR("Page change but not saved. Continue?") %>')}"><%= TR("Project data") %></a></td>
<td align="center" class="topmenu" valign="middle"><a href="../cases/Sagskort.asp?ID=<%=ID%>" onclick="if(gv_changeHaveBeenMade){return window.confirm('<%= TR("Page change but not saved. Continue?") %>')}"><img src="../Grafik/newMenuProjects.png" alt="" border="0"></a><a href="../cases/Sagskort.asp?ID=<%=ID%>" onclick="if(gv_changeHaveBeenMade){return window.confirm('<%= TR("Page change but not saved. Continue?") %>')}"><%= TR("Project card") %></a></td>
</tr>
</table>
I have this table with a single row and lot of <td>
in it which contains a picture and some text that links to other pages that updates in a frame below the menu items i want to highlight.
Currently I am working with this piece of code but cannot get it to work properly.
function highlight_data() {
var table = document.getElementById('display-table');
var cells = table.getElementsByTagName('td');
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
cell.onclick = function () {
var tdId = this.parentNode.cellIndex;
var tdNotSelected = cells;
for (var data = 0; data < tdNotSelected.length; data++) {
tdNotSelected[data].style.backgroundColor = "";
tdNotSelected[data].classList.remove('selected');
}
var tdSelected = cells[tdId];
tdSelected.style.backgroundColor = "yellow";
tdSelected.className += " selected";
}
}
} //end of function
window.onload = highlight_data;
somehow if I use rowIndex
insted af cellIndex
at this.parentNode.cellIndex
it can highlight a single cell onclick bit i highlights the cell next to the one i click in the selected row in my test.
Bear in mind I would like this in pure JS if possible thanks.
Edit: Rayon's answer worked partly, I did not mention that it's a menu that updates a frame with the content the links link to, Rayon's answer highlight the cell until the frame is finished loading the new page and then the highlight disappears.