Home AgeRage.net Forum Cheats News Hosting Shop About Links


Links
shop

download

facebook
Go Back   AgeRage.net Forum > ..::General AgeRage::.. > Designers Studio > Web Development & Designing


Thread: JavaScript; Dynamically Switching CSS
Web Development & Designing Got any web designing skills? Or maybe a question about a script that doesn't work? Use this forum to talk about this type of thing.

Reply

 
LinkBack Thread Tools


  #1 (permalink)  
Join Date: 29 Sep 2005
Posts: 928
2nd~0v3R|r!de's Avatar
Old 02-08-2006, 14:47
Bronze Dragon
JavaScript; Dynamically Switching CSS

This is just the way I do it, there is plenty of other ways.
This is the easyest. When you get into JavaScript or web design in general you'll notice IE is a bitch, especially when you get into DOM/AJAX/DHTML.

This code works in IE 6 (proberly 4 and 5 too), Firefox and i'm pretty sure Opera too but I haven't tested it yet as Opera is a pretty good standard complient browser but with a very small user base.
Code:
<link id="CSSElement" type="text/css" rel="stylesheet" media="all" href="styles.css" />
function StyleSheetSwitch(CssUrl)
{
	document.getElementById('CSSElement').href = CssUrl + '.css';
}
Give your link tag an Id attribute and set that to "CSSElement". Then create a few links;
Code:
<a href="javascript:;" onclick="StyleSheetSwitch('styles_red');"
When clicked the onclick attribute triggers the function 'StyleSheetSwitch' which then finds the link tag and changes the href attribute.

Tip; use document.write to add the CSS swapping links so if the user doesn't have JavaScript enabled, the page doesn't have broken links.

Note;
<a href ="index.html"></a>

a = tag
href = attribute
index.html = value

Last edited by 2nd~0v3R|r!de; 02-08-2006 at 14:54..
Reply With Quote

AgeRage.net Shop - Buy your valid CD-Keys

  #2 (permalink)  
Join Date: 24 Jan 2005
Location: :.Middle Earth.:
Age: 21
Posts: 7,113
Virtuosofriend's Avatar
Old 02-08-2006, 18:01
AgeRage Founder
This cannot be changed from the CSS file itself, using the .ahover etc? That's how i do it.

Your ideas seems very very clever.

Reply With Quote
  #3 (permalink)  
Join Date: 29 Sep 2005
Posts: 928
2nd~0v3R|r!de's Avatar
Old 02-08-2006, 19:17
Bronze Dragon
Quote:
Originally Posted by Virtuosofriend
This cannot be changed from the CSS file itself, using the .ahover etc? That's how i do it.
You can edit certain rules within the CSS file, but this changes the WHOLE CSS file. If you had to change the style of all P, SPAN, A, and STRONG tags then it would be easyer for you to create a new CSS file, rather than editing each one indivdually.

Say for example you want to create 3 different themes for your site, you can have everything change without having more than one page. It's more of a novalty but it can be very useful if you need a text only version of your site, inverted images and text or a larger text version of your site.

This is more of a DHTML/AJAX feature that's easy and allows people to get into JavaScript easily.

Last edited by 2nd~0v3R|r!de; 02-08-2006 at 19:19..
Reply With Quote
  #4 (permalink)  
Join Date: 24 Jan 2005
Location: :.Middle Earth.:
Age: 21
Posts: 7,113
Virtuosofriend's Avatar
Old 02-08-2006, 22:03
AgeRage Founder
I am way too lazy and busy with Civil 3 right now, i've been playing it for 17hrs straight , do you think you could add that code in a html page, so i can see it? I will show ya, how to make cool dhtml menus (collapsable). Very neat shit, i just need to find some time to actually post the code

Reply With Quote
  #5 (permalink)  
Join Date: 29 Sep 2005
Posts: 928
2nd~0v3R|r!de's Avatar
Old 02-08-2006, 22:29
Bronze Dragon
Quote:
Originally Posted by Virtuosofriend
I am way too lazy and busy with Civil 3 right now, i've been playing it for 17hrs straight , do you think you could add that code in a html page, so i can see it? I will show ya, how to make cool dhtml menus (collapsable). Very neat shit, i just need to find some time to actually post the code
Yep, will do.
I'l just upload a quick test site to a crappy free host, sorry about the ad's if they have any.

I'm really getting into this whole "web 2.0" thing, you know AJAX/DHTML. Great stuff.

[edit][Only registered and activated users can see links. ]
Sorry about the host, I just had to create a account and that. Free with ads.
Click either the blue text to use "styles.css" or the "No background, show span's, edit div's" text to use "styles2.css".
Very quick and crappy example, sorry about that. I was eating dinner at the same time as making it.[/edit]

Last edited by 2nd~0v3R|r!de; 02-08-2006 at 22:56..
Reply With Quote
  #6 (permalink)  
Join Date: 24 Jul 2007
Location: AgeRage.net Cosmos
Posts: 6
8zack8's Avatar
Old 31-01-2008, 10:43
8zack8 8zack8 is offline
Recruited Rager
Guys! i need Some Tips to Adding JavaScript Into my Blog.......

'Couse It Always Failure......
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 15:46.

Latest Threads

About AgeRage Forum

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
AgeRage.net - 'Feeding Your Cheating Obsession'
Page generated in 0.18684 seconds with 12 queries