Posted on May 8th, 2011
1582 views Whats the point in having a style switcher I hear you ask? Well… It helps with user interaction. Adds some uniqueness to your site, allows users to change the looks of the site. The list goes on! Well, today, im going to show you how its done. Its nothing complex so you dont need to worry about failing. OK, Lets Go. Step 1: Create your seperate stylesheets, and name them whatever you want. Step 2: now, insert the following code into an html, where you want the style switcher to be: $(".styleswitch").click(function(){$('link[rel=stylesheet]').attr('href,$(this).attr('rel'));});Dark | Light The above code is all that you need to create a styleswitcher.from the top line, its saying the element with the class of styleswitch, when clicked, will change the stylesheet of the document. The stylesheet is linked on the anchor tags under a “rel” attribute. Thats all to it! Jazzing up your sites could never be easier. |