We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 01/10/08


Tagged

style jquery example switcher


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

abhisek
martingoldszein
chrisaiv


jQuery Simple Style Switcher


Published in: JavaScript 


Very simple style switcher using jquery. Takes 3 links with id's on each. When one is clicked various styles are removed, then a new one is added.

  1. /** @id sipleSwitcher
  2. * @classDescription Very simple style switcher using jQuery
  3. */
  4. $(document).ready(function(){
  5. $('#styleSwitch .button').bind('click', function(){
  6. $('body').removeClass();//remove all the other classes
  7. $('#styleSwitch .button').removeClass('selected');
  8. $(this).addClass('selected');
  9. switch(this.id){
  10. case 'style1':
  11. $('body').addClass('style1');
  12. break;
  13. case 'style2':
  14. $('body').addClass('style2');
  15. break;
  16. case 'style3':
  17. $('body').addClass('style3');
  18. break;
  19. }
  20. return false;
  21. });
  22. });

Report this snippet 

You need to login to post a comment.