jquery - Toggle between stylesheets with one button -



jquery - Toggle between stylesheets with one button -

i'd toggle between 2 stylesheets using single button. code have is:

<link id="style1" rel="stylesheet" type="text/css" href="style.css" /> <link id="style2" rel="stylesheet" type="text/css" href="styleinvert.css" disabled="disabled" /> <script> function toggle() { var el1 = document.getelementbyid("style1"), el2 = document.getelementbyid("style2"); if( el1.disabled == "disabled" ) { el1.disabled = undefined; el2.disabled = "disabled"; } else { el1.disabled = "disabled"; el2.disabled = undefined; } } </script> <a href="#" onclick="toggle()">invert</a>

however causes stylesheet temporarily disappear between deactivating first 1 , activating new one.

is there improve way this? ideally i'd add together little snippet of style sec stylesheet seen need alter few things font color etc.

here's basic illustration of mean adding class body , writing override styles...

function toggle(){ $('body').toggleclass('style2'); } // css p{ color:green; } .style2 p{ color:red; }

the jquery toggle class docs: http://api.jquery.com/toggleclass/

jquery css button stylesheet

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -