Jump to content

Changing CSS


Xune

Recommended Posts

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

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

thanks, will try this in a moment, and post back if it works..Thanks againKind Regards, Nathan

Link to comment
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...