Skip to content

Instantly share code, notes, and snippets.

@Bijesse
Created August 16, 2016 18:22
Show Gist options
  • Save Bijesse/2bd1a0e863835921e4baedd2ab4ff8ee to your computer and use it in GitHub Desktop.
Save Bijesse/2bd1a0e863835921e4baedd2ab4ff8ee to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=2bd1a0e863835921e4baedd2ab4ff8ee
<!DOCTYPE html>
<html>
<head>
<title>Color Changer Project</title>
</head>
<body>
<div>
<button type="button" id="button">Change</button>
</div>
</body>
</html>
var colors = ["blue", "red", "yellow", "green", "orange", "purple"];
var index = 0;
$( document ).ready(function()
{
$('#button').click(function change(){
if(index === colors.length) {
index = 0;
}
$("body").css("background-color", colors[index]);
//console.log(colors[index]);
index++;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment