Solved

javascript onload

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

626 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