...

View Full Version : Problem with <TR> Tag



Elcid32
07-28-2006, 12:09 AM
Hello Forum:

I have a question regarding the following code snippet:



var rows=tableobj.getElementsByTagName('tr');
for(i=0;i<rows.length;i++){
rows[i].onmouseover = function(){this.style.backgroundColor="gold";}
rows[i].onmouseout = function(){this.style.backgroundColor="#FFFFFF";}
}

This peice of code will not work, no matter what I try. I have verified that there are 20 <tr> tags in tableobj. If I change the code to
var rows=tableobj.getElementsByTagName('td'); it works properly (by highligting the individual cells.) What am I doing wrong? Thanks.

Shawn

vwphillips
07-28-2006, 07:30 PM
as expected this works for me


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function Add(){
var tableobj=document.getElementById('fred');
var rows=tableobj.getElementsByTagName('TR');
for(i=0;i<rows.length;i++){
rows[i].onmouseover = function(){this.style.backgroundColor="gold";}
rows[i].onmouseout = function(){this.style.backgroundColor="#FFFFFF";}
}}
/*]]>*/
</script></head>

<body onload="Add();">
<table id="fred" cellpadding="0" cellspacing="0" border="1">
<tr>
<td width="100" >tttttttt</td>
</tr>
</table>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum