This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes  Change the background color of a row in a table upon mouse click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark " Change the background color of a row in a table upon mouse click" Watch " Change the background color of a row in a table upon mouse click" New topic
Author

Change the background color of a row in a table upon mouse click

shwetha nataraj
Greenhorn

Joined: Apr 26, 2010
Posts: 3
Hi,

I have a html zebra table which is generated dynamically. Upon clicking on any of the rows that row should get highlighted. I am unable to achieve this due to the css specified for achieving the zebra pattern for the table.

The code for the above is:

html:



main.css:



approver.js:


Please provide some help on this
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
As far as I can see, the css sets the color for the table cells (TDs), but you are attempting to set a color for the entire row (TR). Perhaps try to change the style of the cells instead?
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
I am not a css expert but...

You explicitly set the color white for your td.



it seems that no matter what you do to your tr tag, your td is still white.

If you delete that line above it works.
I tried it and it worked


Bye,
Nicola
shwetha nataraj
Greenhorn

Joined: Apr 26, 2010
Posts: 3
Hi Nicola,

By removing the line that sets the color white for the td will help in highlighting only the white rows in the table but the blue rows in the table will not get highlighted upon clicking on it.


Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
With javascript function you are highlighting rows, but i fear the styles applied to cells remains unchanged.

You could act accordingly: You could change styles of TD's (instead of TR's) inside your javascript file or set the initial styles for TR's (instead of TD's) in your css file.
shwetha nataraj
Greenhorn

Joined: Apr 26, 2010
Posts: 3
Thanks Nicola.. That helped us resolve the issue
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change the background color of a row in a table upon mouse click
 
Similar Threads
problem in running a servlet
changing link background image dynamically
location.href not working on FireFox 3.5
displaying multiple columns in html table in jsp from mysql database
fixed header, problem with alignment, must support all browsers