Solved

javascript onload

Posted on 2011-09-06
4
288 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
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

770 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