Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Alternating row color and mouseover row color not working in IE7 or firefox

Posted on 2006-11-19
5
Medium Priority
?
1,328 Views
Last Modified: 2008-01-09
I've obviously gone wrong somewhere but this code looks right so any ideas where I have gone wrong??

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.row1 {
      background-color:#CCCCCC;
      color:#333333;
}

.row2 {
      background-color:#FFFFFF;
      color:#333333;
}
.rowHover1 {
      background-color:#000000;
      color:#ffffff;
}
-->
</style>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="33%">Heading</td>
    <td width="33%">Heading</td>
    <td width="33%">Count</td>
  </tr>
  <tr class="row1" onmouseover="this.class='rowHover1'" onmouseout="this.class='row1'">
    <td>1</td>
    <td>link1</td>
    <td>count1</td>
  </tr>
  <tr class="row2" onmouseover="this.class='rowHover1'" onmouseout="this.class='row2'">
    <td>2</td>
    <td>link2</td>
    <td>count2</td>
  </tr>
  <tr class="row1" onmouseover="this.class='rowHover1'" onmouseout="this.class='row1'">
    <td>3</td>
    <td>link3</td>
    <td>count3</td>
  </tr>
  <tr class="row2" onmouseover="this.class='rowHover1'" onmouseout="this.class='row2'">
    <td>4</td>
    <td>link4</td>
    <td>count4</td>
  </tr>
</table>
</body>
</html>
0
Comment
Question by:abenbow
5 Comments
 
LVL 6

Accepted Solution

by:
iscode earned 2000 total points
ID: 17975568
try this

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.row1 {
     background: #CCCCCC;
     color: #333333;
}

.row2 {
     background: #FFFFFF;
     color:#333333;
}
.rowHover1 {
     background: #000000;
     color: #ffffff;
}
-->
</style>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="33%">Heading</td>
    <td width="33%">Heading</td>
    <td width="33%">Count</td>
  </tr>
  <tr class="row1" onmouseover="this.className='rowHover1'" onmouseout="this.className='row1'">
    <td>1</td>
    <td>link1</td>
    <td>count1</td>
  </tr>
  <tr class="row2" onmouseover="this.className='rowHover1'" onmouseout="this.className='row2'">
    <td>2</td>
    <td>link2</td>
    <td>count2</td>
  </tr>
  <tr class="row1" onmouseover="this.className='rowHover1'" onmouseout="this.className='row1'">
    <td>3</td>
    <td>link3</td>
    <td>count3</td>
  </tr>
  <tr class="row2" onmouseover="this.className='rowHover1'" onmouseout="this.className='row2'">
    <td>4</td>
    <td>link4</td>
    <td>count4</td>
  </tr>
</table>
</body>
</html>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17975676
How about this:


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Zvonko &#42;</title>
<style type="text/css">
<!--
.row1 {
     background-color:#CCCCCC;
     color:#333333;
}

.row2 {
     background-color:#FFFFFF;
     color:#333333;
}
.rowHover1 {
     background-color:#000000;
     color:#ffffff;
}
-->
</style>
<script>
function highLight(e){
  var theRow = (e.target)?e.target:e.srcElement;
  while(theRow&&theRow.nodeName!="TR"){
    theRow = theRow.parentNode;
  }
  if(theRow){
    if(e.type.indexOf("out")>0){
      theRow.className=theRow.getAttribute("orgClass");
    } else {
      theRow.setAttribute("orgClass",theRow.className);
      theRow.className="rowHover1";
    }
  }
}
</script>
</head>

<body>
<table width="100%" onmouseover="highLight(event)" onmouseout="highLight(event)">
  <tr>
    <td width="33%">Heading</td>
    <td width="33%">Heading</td>
    <td width="33%">Count</td>
  </tr>
  <tr class="row1">
    <td>1</td>
    <td>link1</td>
    <td>count1</td>
  </tr>
  <tr class="row2">
    <td>2</td>
    <td>link2</td>
    <td>count2</td>
  </tr>
  <tr class="row1">
    <td>3</td>
    <td>link3</td>
    <td>count3</td>
  </tr>
  <tr class="row2">
    <td>4</td>
    <td>link4</td>
    <td>count4</td>
  </tr>
</table>
</body>
</html>


0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17975702
<script >
var oldbg="#ffffff";
function lighton(i){
        oldbg=i.style.backgroundColor;
        i.style.backgroundColor="CCCCCC";
}
function lightoff(i) { i.style.backgroundColor=oldbg; }
</script>
...
<tr  onMouseOver=lighton(this) onMouseOut=lightoff(this)>
...
0
 

Author Comment

by:abenbow
ID: 17975759
bingo, thanks
0
 
LVL 6

Expert Comment

by:iscode
ID: 17975765
your welcome
glad I could help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question