jQuery Simple Style Switcher


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.