javascript - Toggle between 3 classes using toggleclass -


i have 3 images want switch between. put each 1 of them in class & change it's image in css. can switch between 2 classes when add third 1 code doesn't work. class of them can starting one.

    $('.one').click(function(){                                      $(this).toggleclass("two");         $(this).toggleclass("one");      });      $('.two').click(function(){                                      $(this).toggleclass("one");         $(this).toggleclass("two");      }); 

when add line:

        $(this).toggleclass("three");  

it doesn't toggle @ all....

do know method in can put of them in 1 function ?

thanks.

example fiddle: http://jsfiddle.net/kdfev/

this code allow cycle through sequence of defined classes

$('.one, .two, .three').click(function() {                                  this.classname = {        3 : 'one', one: 'two', two: 'three'     }[this.classname]; }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -