/ Published in: jQuery

This is perfect for "cycling" items...
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE html> <html> <head> <title>JS literations</title> <meta charset="UTF-8"> <script language="Javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var volumes = ["10", "20", "30", "40", "50", "55", "60", "80", "100"]; var currentVolume = -1; $("#buttonClick").click(function(){ currentVolume = ( ++currentVolume % volumes.length ); $("#log").html("volume: " + volumes[currentVolume] + " %"); return false; }); $("#buttonClick").click(); }); </script> </head> <body> <a href="#" id="buttonClick">change volume<a> <p id="log">volume</p> </body> </html>
Comments
