Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Inspecting the source code and how it changes as you change themes, it is really quite simple. Digg is harnessing the awesomeness of CSS to drastically change content by simply changing the class of an element. All you have to do is this:
And then you can have your themes:
All
switchThemeneeds to then do is change the class oftheme_viewerto the class passed:Your CSS stylesheets can then do whatever the different styles call for:
here is an example of this at work
As mentioned in the comments by J-P and in edeverett’s answer, it is not a good idea to have your events inline as I have them in this example (ie, with the
onclickattribute). I did it for simplicity, but it’s not a good idea. The better idea is to wait for your document to load and attach the event handlers dynamically with Javascript. This is known as unobtrusive Javascript, and it is a Good ThingTM.An example of the above example following good practices would look like this:
And then we use this cross browser addEvent function (written by John Resig, author of jQuery):
To add the event handlers:
It might be a little more verbose than inline Javascript, but it is worth it. I know you said you’d like to avoid jQuery, but something as simple as this makes you start appreciating the library, as you could do it with jQuery with something as simple as this: