954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Want to change color on click!?

I am displaying data in a table on one of my web pages. When the user clicks on a row, I want that row ONLY to change color. I'd settle for that cell. I have a css file referenced on the page with two styles, td_on and td_off, which have same settings except for the background colors. I put the "class" tag in the td like so:

I have tried to use the onclick action to change the class to the td_on style like so, onclick="class=td_on" but this does NOT cause any changes. Can someone tell me what the proper syntax for doing this is ... or maybe an easier way to accomplish what I want???!

TIA

vcombs
Newbie Poster
2 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Maybe u could try onclick="id='td_off'" . I'm not exacly shure if it is the write sintax, maybe it has to be something infront of " style='td_of' ", like TD or something. But I think this works.I'm new here to! ;)
Try and reply!

Ok I tried it myselfe and the only problem is vith IE couse u have to alow a "popup" if u wont it to work. :(
Firefox goes OK! :o

pajac
Light Poster
33 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Use ID instead of class in css.

dont .something but #something ok.

pajac
Light Poster
33 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

I am displaying data in a table on one of my web pages. When the user clicks on a row, I want that row ONLY to change color. I'd settle for that cell. I have a css file referenced on the page with two styles, td_on and td_off, which have same settings except for the background colors. I put the "class" tag in the td like so:

I have tried to use the onclick action to change the class to the td_on style like so, onclick="class=td_on" but this does NOT cause any changes. Can someone tell me what the proper syntax for doing this is ... or maybe an easier way to accomplish what I want???!

TIA

Here - if you haven't gotten it, try this:

This should be your TD in your HTML:

<td class="out" onMouseOver="this.className='over'" onMouseOut="this.className='out'"><a href="page.php">LINK</a></td>

Then in your stylesheet:

.over { background-color:#D0C0A9; padding-top: 2px; padding-bottom:2px;} 
.out { background-color: #E1D4C0; padding-top: 2px; padding-bottom:2px;}

That should do it for ya!

Let me know if you have problems, I'd be glad to help.

Shannon Second Platform

2ndPlatform
Junior Poster in Training
61 posts since Nov 2004
Reputation Points: 15
Solved Threads: 0
 

God solution 2ndPlatform! :D
I'm missing some experiences at this field, but doing on that too. :mrgreen:

pajac
Light Poster
33 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

I am displaying data in a table on one of my web pages. When the user clicks on a row, I want that row ONLY to change color. I'd settle for that cell. I have a css file referenced on the page with two styles, td_on and td_off, which have same settings except for the background colors. I put the "class" tag in the td like so:

I have tried to use the onclick action to change the class to the td_on style like so, onclick="class=td_on" but this does NOT cause any changes. Can someone tell me what the proper syntax for doing this is ... or maybe an easier way to accomplish what I want???!

TIA ok so here is what i used. i got the same situation you did. kinda. anyway if your just changing the background of a cell onClick do this and for rows this now obviously you can change the colors as needed or desired but this worked for me.

billbob12345678
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
MasonShew
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You