'Set JavaScript variable to match another variable on click with memory

I'm looking to allow users to change the images on a site, and save the new images in local storage.

There are 5 divs with background images (can all be declared in variables). When each is clicked, it brings up a container that includes 10 image options (more variables). When the user clicks an option, the container closes and some jQuery sets the background image of the div that was clicked to the image that was clicked.

Having some trouble wrapping my head around the variables - the container is global, so the script needs to remember which div was clicked and only change the background image of that div. And to save it in local storage, the variable for the background image needs to be saved as the image URL selected. Is there some dynamic variable or array work to be done here? Appreciate the help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source