Jump to content

hi can any one help me


Guest phani

Recommended Posts

i have 4 cells. When i clicked on one cell i want to chage that cell color

When you say cell, do you mean table cell?
<html><head><style type="text/css">td {width: 200px;height: 150px;background-color: #000000;}</style></head><body><table><tr><td onmousedown="this.style='background-color: #ff0000;'" onmouseup="this.style=''"></td><td onmousedown="this.style='background-color: #00ff00;'" onmouseup="this.style=''"></td></tr><tr><td onmousedown="this.style='background-color: #0000ff;'" onmouseup="this.style=''"></td><td onmousedown="this.style='background-color: #ffff00;'" onmouseup="this.style=''"></td></tr></table></body></html>

Try that code here to see how it workshttp://www.w3schools.com/html/tryit.asp?fi...e=tryhtml_basicIf you want to keep the color after you click the table cell, you exchange onmousedown/onmouseup with <td onclick="this.style='background-color: #??????;'"></td>

Link to comment
Share on other sites

O.M.G.I MADE SOMETHING WORK WITH CSS!:)

<html><head><style type="text/css">td {width: 200px;height: 150px;background-color: #000000;}td:active{background-color:#eeeeee;}</style></head><body><table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table></body></html>
Hahah! I beat jonas! :)the red parts are the parts where you change the color of the td. the td:active means when the table cell is clicked, and the td part is the table in general. Good luck!
Link to comment
Share on other sites

Hahah! I beat jonas! the red parts are the parts where you change the color of the td.
Congrats... :)then again, :active isn't the way to go if you want to make the background-change last until you reload... I guess mozilla doesn't really support JavaScript that well, or at least not HTML events...
Link to comment
Share on other sites

Congrats... :)then again, :active isn't the way to go if you want to make the background-change last until you reload... I guess mozilla doesn't really support JavaScript that well, or at least not HTML events...

Oh, psh. Just accept your defeat. :)Also,
then again, :active isn't the way to go if you want to make the background-change last until you reload
What?
Link to comment
Share on other sites

Chocolate570: too bad :active only works for links with IE... :)As for the JavaScript code, I think it should be this.style.backgroundColor = 'something', not this.style='background-color: something'.Personally, I'd use both the :active pseudo-class plus Javascript for IE.

Link to comment
Share on other sites

What?
Um, okay...tag_name:active I think would be the same as onmousedown followed by something else for onmouseup.However, if you want the color of the cell to remain that color, you would use onclick="this.style.etc..." :active won't do that I think...
Link to comment
Share on other sites

I think it should be this.style.backgroundColor = 'something', not this.style='background-color: something'.
I find that both work as long as you use onclick="this.style='blahblah' "Don't mix ' and "...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...