...

View Full Version : Change Background Color of Row When Selected



jason_kelly
06-21-2012, 09:19 PM
Hello,

Given the following code below, how can I modify it such that it would change the background color of the selected row. It currently works great if a single cell is selected but i'd like to have it modified such that the selected row color is changed:



<html>
<head>
<script type="text/javascript">
var ie = document.all
var ns = document.getElementById && !ie
function rowclick(e) {
var obj = ns ? e.target : event.srcElement
if (obj.tagName=="TD") {
obj.style.background="red"
obj.onblur=function() {
obj.style.background="white"
}
}
}
document.onclick=rowclick
</script>
</head>
<body>
<table width="320" cellspacing="1" border="1">
<tr>
<td width="127">Bananas</td>
<td width="101">123</td>
<td>red</td>
</tr>
<tr>
<td width="127">Pears</td>
<td width="101">456</td>
<td>blue</td>
</tr>
<tr>
<td width="127">Mangos</td>
<td width="101">789</td>
<td>green</td>
</tr>
<tr>
<td width="127">Apples</td>
<td width="101">012</td>
<td>yellow</td>
</tr>
</table>
</body>
</html>



Any help with this is greatly appreciated.

Much thanks for all your help and support in advance.

Cheers,

Jay

BubikolRamios
06-22-2012, 05:50 AM
How about like:



obj.parentNode.style.background="red"


Out of head.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum