Guest phani Posted October 24, 2005 Share Posted October 24, 2005 i have 4 cells. When i clicked on one cell i want to chage that cell color Link to comment Share on other sites More sharing options...
Jonas Posted October 24, 2005 Share Posted October 24, 2005 i have 4 cells. When i clicked on one cell i want to chage that cell color<{POST_SNAPBACK}> 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 More sharing options...
Chocolate570 Posted October 24, 2005 Share Posted October 24, 2005 Unless it's me, that script does not work in firefox. I'll try to work on it, unless someone beats me. Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 24, 2005 Share Posted October 24, 2005 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 More sharing options...
Jonas Posted October 24, 2005 Share Posted October 24, 2005 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 More sharing options...
Chocolate570 Posted October 26, 2005 Share Posted October 26, 2005 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...<{POST_SNAPBACK}> 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 reloadWhat? Link to comment Share on other sites More sharing options...
F-Man Posted October 26, 2005 Share Posted October 26, 2005 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 More sharing options...
dave Posted October 26, 2005 Share Posted October 26, 2005 how do you save a css file? with blahblahblah.css ? Link to comment Share on other sites More sharing options...
F-Man Posted October 26, 2005 Share Posted October 26, 2005 how do you save a css file? with blahblahblah.css ?<{POST_SNAPBACK}> Yes. Link to comment Share on other sites More sharing options...
Jonas Posted October 26, 2005 Share Posted October 26, 2005 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 More sharing options...
Jonas Posted October 26, 2005 Share Posted October 26, 2005 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 More sharing options...
F-Man Posted October 26, 2005 Share Posted October 26, 2005 I find that both work as long as you use onclick="this.style='blahblah' "Don't mix ' and "...<{POST_SNAPBACK}> Both work in IE, yes. But the latter is correct syntax one. Link to comment Share on other sites More sharing options...
Jonas Posted October 26, 2005 Share Posted October 26, 2005 Both work in IE, yes. But the latter is correct syntax one.Works in Opera as well... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now