Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Color Switching 2

Status
Not open for further replies.

kylebellamy

Programmer
Jan 24, 2002
398
US
I've been looking around in google and not finding what I wanted so I've come back to the place that always has the answers I need.

I am looking for a way to change all the <h> colors and a few minor graphics to a different color based on what the user clicks. In this case, it starts out a green but there is the option to click orange, red and blue.

I was hoping to avoid swapping the entire style sheet and re-loading the page but I can't seem to find anything that references just that switch.

Is this a possibility or something that is way more work than it's worth?

Thanks,
Kyle

 
Hi

You are very kind. Pity that only one star is allowed to give to a member in a thread... :)

Anyway, there must be some kind of after-4th July syndrome, because otherwise the other MVPs would give those answers faster than me.

Feherke.
 
If you are switching a load of things en-masse you may want to simply add a class attribute to the body tag then reference the changing elements via that.

For instance:
Code:
h3 { color:#f00; }

body.othercolours h3 { color:#ff9933; }

Then apply the new class to the body via javascript?

Might not be quite what you need, but it struck me that it's easier to change 1 element's class then a whole bunch of elements.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Hi

You know, if you use alternate stylesheets, then the visitor can change between them even if has JavaScript disabled. It works with :
[ul]
[li]FireFox : View | Page Style[/li]
[li]SeaMonkey : View | Use Style[/li]
[li]Opera : View | Style[/li]
[li]Konqueror : I have none handy now...[/li]
[/ul]
Of course, Explorer 6 has no such feature. No idea about Explorer 7.

The only problem is that the style selection is not kept after you navigate forward from the given page. But for FireFox there is a solution, the Style Sheet Chooser II extension is able to make the style selection to persist over the given site.

I hope that similar features will be available in all browsers. So I prefer implementing look & feel changes with alternate stylesheets, and not with on-the-fly changes made by JavaScript.

Feherke.
 
I'm thinking I'll go with the more universally easy way of using javascript since using internal switches in browsers in more of a power user thing and would require details that would generally annoy most casual browsers.

Maybe I should have a script in place that detects if javascript is not enabled and will let them know it is required for some features of the site.

 
Hi

kylebellamy said:
I'm thinking I'll go with the more universally easy way of using javascript since using internal switches in browsers in more of a power user thing and would require details that would generally annoy most casual browsers.
I did not suggested anything. The only thing I wrote ( hmm... or at least intended to... ) is that changing look & feel with alternate stylesheets is supported by the browsers themselves too. And that makes me think that should be the preferred way.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top