how to change background color in array with javascript.
let back_color = [‘#FFEEDE’, ‘#EAFFE2’, ‘#FFEEDE’, ‘#EAFFE2’, ‘#FFEEDE’, ‘#EAFFE2’, ‘#FFEEDE’, ‘#EAFFE2’, ‘#FFEEDE’, ‘#EAFFE2’];
let i = 0;
$("#prev").click(function () {
i = i < back_color.length ? --i : 0;
$('.back-color').css("background", "" + back_color[i] + "" );
});
$("#next").click(function () {
i = i < back_color.length ? ++i : 0;
$('.back-color').css("background", "" + back_color[i] + "" );
});
html ==>
change color
2
Answers
Below code will change the value of element in array –
Is this what you’re looking for?
Sources (Getting a random value from a JavaScript array) & (https://bobbyhadz.com/blog/javascript-change-background-color-on-click)