Xune Posted March 8, 2008 Share Posted March 8, 2008 Hello, I have seen this done before, and was wondering if anyone knew how to do it.I once saw a page, that when you clicked on a div in their site... it changed the colorso likeNot ClickedWhite page with black text.ClickedBlack page with white text.understand my question? Link to comment Share on other sites More sharing options...
Peppe L-G Posted March 8, 2008 Share Posted March 8, 2008 I think:For background color:<input type="button" value="Change color" onclick="document.body.style.background = 'red';">For text color: <input type="button" value="Change color" onclick="document.body.style.color = 'red';">If you want to change these things in a div instead of the whole body, just replace body with getElementById('the id on the div') Link to comment Share on other sites More sharing options...
Xune Posted March 8, 2008 Author Share Posted March 8, 2008 thanks, will try this in a moment, and post back if it works..Thanks againKind Regards, Nathan Link to comment Share on other sites More sharing options...
Xune Posted March 8, 2008 Author Share Posted March 8, 2008 Ok, that worked, and when I looked at it, that is not quite what I want...I don't want it to be a button, but a piece of code, that I have, that makes it so when you click anywhere in that div, it changes the color and background of the div...though, if nobody can help, I guess I will use this... Link to comment Share on other sites More sharing options...
Ingolme Posted March 8, 2008 Share Posted March 8, 2008 This code will load a different CSS stylesheet for the page when you click on the div.This goes into the <head> of the document:<link href="style.css" rel="stylesheet" type="text/css" id="stylechange" />This goes in the <body> of the document: <div id="object">Give this a div width and height or put some content into it</div><script type="text/javascript">document.getElementById("object").onclick = function() {(document.getElementById("stylechange").href=="newstylesheet.css")?document.getElementById("stylechange").href = "style.css":document.getElementById("stylechange").href = "newstylesheet.css";}</script> Link to comment Share on other sites More sharing options...
jeffman Posted March 10, 2008 Share Posted March 10, 2008 In some situations, this might be simpler and more direct: document.getElementById("myDiv").onclick = function() {this.className = "myDivsOtherClassName";} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.