Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  .red { color: red; }
  .blue { color: blue; }
  .green { color: green; }
  .black { color: black; }
  .purple { color: purple; }
</style>
</head>
<body>
  <p id="hello">Hello World</p>
  
  <div>Click me</div>
</body>
</html>
 
var classArray = ['red', 'green', 'blue', 'black', 'purple'];
$('div').click(function() {
  $('p').toggleRotate(classArray);
});
(function($) {
  $.fn.toggleRotate = function(classes) {
    
    $(this).toggleClass(function() {
      var l = classes.length;
      for (var i = 0; i < l; i++) {
        if ($(this).hasClass(classes[i])) {
          var next = i + 1 >= l ? 0 : i + 1;
          return classes[i] + ' ' + classes[next];
        }        
      }
      // If it makes it here return the first current value
      return classes[0];
    });
  };
})(jQuery);
  
  
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers