1

I'd like to change the css of a page. I see two ways of doing it :

Using the Jquery .css function to change every tag in the html. example :

$("body").css("background : red")

Or disabling the current css stylesheet and enable a new one.

example:

function switch_style ( css_title )
{
// You may use this script on your site free of charge provided
// you do not remove this notice or the URL below. Script from
// http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
  var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;
    i < link_tag.length ; i++ ) {
    if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) &&
      link_tag[i].title) {
      link_tag[i].disabled = true ;
      if (link_tag[i].title == css_title) {
        link_tag[i].disabled = false ;
      }
    }
  }
}

Which way is the more efficient ? Or maybe there is better ways ?

4
  • 12
    There's a third option: giving the body an extra class and using body.class2 in your CSS instead of using a second stylesheet. Commented Jun 23, 2013 at 23:46
  • 3
    @TomvanderWoerdt - Make that an answer. Commented Jun 23, 2013 at 23:48
  • @TomvanderWoerdt You should put this as answer :) Commented Jun 23, 2013 at 23:48
  • Okay, added it as an answer. Commented Jun 24, 2013 at 0:00

1 Answer 1

6

There's a third option: giving the body an extra class and using body.class2 in your CSS instead of using a second stylesheet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.