I am extremely new to javascript, and I just can not wrap my head around for loops and variable lists. It seems like every tutorial half way explains it and then rambles/mubles on the rest of the way and doesn't really make it clear.
So, I decided to make a div a different color for each time it's clicked, which iterates through four colors.
HTML:
<div class="myDiv"></div>
CSS:
.myDiv {
display: block;
height: 100px;
width: 150px;
background: #ea5243;
}
JavaScript (using jQuery):
$(document).ready(function() {
var colors = ["#b8d30b", "#0099cc", "#e63f35", "#fbd108"];
for(var i in colors) {
$(".myDiv").on("click", function() {
$(this).css("background", colors);
});
}
});
Obviously this will not work, but as you can see, I want to rotate through each color code per click.
I have tried googling my problem, but found it hard to phase, therefore no avail. And as I said, I am very new to javascript.