Skip to content

Instantly share code, notes, and snippets.

@zackn9ne
Created October 15, 2014 16:17
Show Gist options
  • Select an option

  • Save zackn9ne/1adf5d942650822aeb55 to your computer and use it in GitHub Desktop.

Select an option

Save zackn9ne/1adf5d942650822aeb55 to your computer and use it in GitHub Desktop.
an infinate loop in js, dependancies are jQuery
<script>
colors = ["aquamarine", "lavender", "blue"]
$(".col-md-4").click(function() {
var current_color = $(this).data("color-index");
console.log(current_color);
current_color++;
if (current_color > colors.length - 1){
current_color = 0;
};
$(this).css("background", colors[current_color]);
$(this).data("color-index", current_color);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment