I have a table where it makes a whole row clickable when a link is added to any cell. What I would like to do is add this script to multiple tables on a page. The problem is the script will only work with one table since it can only be used with id and not class css. How do I add multiple table ids?
window.onload = function(){
ConvertRowsToLinks("results-table"); //My table id
// ConvertRowToLinks("results-table", "results-table2");
// I would like to add results-table2, results-table3 etc...
}
function ConvertRowsToLinks(xTableId){
var rows = document.getElementById(xTableId).getElementsByTagName("tr");
for(i=0;i<rows.length;i++){
var link = rows[i].getElementsByTagName("a")
if(link.length == 1){
rows[i].onclick = new Function("document.location.href='" + link[0].href + "'");
rows[i].onmouseover = new Function("this.className='highlight'");
rows[i].onmouseout = new Function("this.className=''");
}
}
ConvertSideRowsToLinks("sidebar-table");
}
function ConvertSideRowsToLinks(xTableId){
var rows = document.getElementById(xTableId).getElementsByTagName("tr");
for(i=0;i<rows.length;i++){
var link = rows[i].getElementsByTagName("a")
if(link.length == 1){
rows[i].onclick = new Function("document.location.href='" + link[0].href + "'");
rows[i].onmouseover = new Function("this.className='highlight'");
rows[i].onmouseout = new Function("this.className=''");
}
}
}
You can also slice arguments this way you can pass as many ids as you want, and you don’t have to create array explicite: