<div></div>
const appBackground = {backgroundParrent: document};
const backgroundArrayImg = [
'https://placekitten.com/g/200/300',
'https://placekitten.com/g/300/400',
'https://placekitten.com/g/400/200',
];
let bgIndex = 0;
appBackground.backgroundParrent.addEventListener('click', () => {
const url = backgroundArrayImg[(++bgIndex) % backgroundArrayImg.length];
console.log(bgIndex);
document.querySelector('body').style.backgroundImage = `url(${url})`;
});
document.querySelector('body').style.backgroundImage = `url(${backgroundArrayImg[bgIndex]})`;
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.