Solved

javascript onload

Posted on 2011-09-06
4
293 Views
Last Modified: 2012-05-12
<table>
<Tr><Td>Column1</td><td>Column2</td></tr>
<tr><Td>hello</td>John</td><td><a href>Continue</a></td></tr>
<tr><Td>hi</td>Mary</td><td><a href>Continue</a></td></tr>
</table>

When each Continue link is mouse over And each row is mouseover, is it possible
to change the <tr> bgcolor = red for example? and also make Continue text in yellow eg.?
And make sure the Column subject will not be impacted with mouse-over event?

Thanks
0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36487861
assuming that table id is 'table1'
window.onload = function(){
  var rows = document.getElementById("table1").rows;

  for ( var counter = 0; counter < rows.length; counter++)
  {
    var row = rows[ counter ];
    row.onmouseover = function(){
      row.style.backgroundColor = "red";
      var secondCell = row.cells[1];
      secondCell.style.color = "yellow";
    };
    row.onmouseout = function(){
      row.style.backgroundColor = "#fff";
      var secondCell = row.cells[1];
      secondCell.style.color = "black";
    };
  }
};
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 36488036
Check this:
<html>
<head>
<title>Zvonko &#42;</title>
<style>
#myTab tr.rowHow {
  background-color: cornflowerblue;
}
#MyTab a:hover {
  background-color: yellow;
}
</style>
<script>
function hoverRow(e){
  if(!e) e=window.event;
  var theRow = (e.target)?e.target:e.srcElement;
  while(theRow && theRow.nodeName!="TR"){theRow = theRow.parentNode;}
  if(theRow && theRow.rowIndex){
    theRow.className = theRow.className.replace(" rowHow","");
    if(e.type=="mouseover"){theRow.className += " rowHow";}
  }
}
</script>
</head>
<body>
<table id=myTab onMouseOver="hoverRow(event)" onMouseOut="hoverRow(event)" >
<thead>
<Tr class="myHead"><Td>Column1</td><td>Column2</td></tr>
</thead>
<tbody>
<tr><td>hello</td><td>John</td><td><a href="#">Continue</a></td></tr>
<tr><td>hi</td><td>Mary</td><td><a href="#">Continue</a></td></tr>
</tbody>
</table>
</body>
</html>

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 36488126
Zvonko: Great Working.
Another one if you have time. Thanks,
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27292873.html
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 36488149
If you want to use a JS library like jquery, check out this working example:
http://jsfiddle.net/HLUbH/
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

734 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