Solved

javascript onload

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now