Welcome Guest, Not a member yet? Register   Sign In
CSS color scheme switching
#11

[eluser]xwero[/eluser]
[quote author="BoltClock" date="1193654390"]So far I've had no luck in using the DOM to alter the href attribute for my color scheme <link />. The solutions that I found all need me to load all stylesheets in the page head.[/quote]
I have looked at the same javascript functions as you i guess but i found one where the use the window reload function. I haven't tried it myself but it looks like something that should work but as i said in my previous answer you need to set the cookie value.
If i have the time this evening i will try to make a working demo.
#12

[eluser]xwero[/eluser]
Code:
$(function(){
  if($.cookie('csstheme') != null && $.cookie('csstheme') != '')
  {
    $('link[@title=themecss]').attr('href','theme_'+$.cookie('csstheme')+'.css');
  }
  $('a').click(function() {
   var baseurl = $('link[@title=themecss]').attr('href');
   baseurl = baseurl.substr(0,baseurl.lastIndexOf('/')+1);
   $.cookie('csstheme', $(this).text());
   $('link[@title=themecss]').attr('href','theme_'+$(this).text()+'.css');
});
});
This works for me on FF and IE7
I'm using the cookie plugin.

ps : no page refresh needed Wink

update : html
Code:
<html>
<head>
<title>jQuery stylesheet switcher</title>
<script src="jquery-1.2.1.min.js"></script>
<script src="jquery.cookie.js"></script>
<script src="jquery.own.js"></script>
<link rel="stylesheet" type="text/css" title="themecss" href="theme_blue.css" />
</head>
<body>
<h1>I change color</h1>
<a href="#">red</a>
<a href="#">orange</a>
<a href="#">green</a>
&lt;/body&gt;
&lt;/html&gt;
#13

[eluser]BoltClock[/eluser]
I tried that, and it works wonders. Thanks xwero! Big Grin
#14

[eluser]xwero[/eluser]
I made it into a fullblown jquery plugin you can get here




Theme © iAndrew 2016 - Forum software by © MyBB