I would like to be able to change the background image of a <div>
when hovering over a link. Initially, the <div>
should not have a background image when the page loads for the first time.
This is my current setup:
<div class="background">
<a href="#" data-bkgimg="link-1-bkg.jpg">Link 1</a>
<a href="#" data-bkgimg="link-2-bkg.jpg">Link 2</a>
</div>
Here's what I want to achieve on hover:
<div class="background" style="background-image: url('link-1-bkg.jpg');">
<a href="#" data-bkgimg="link-1-bkg.jpg" class="is-active">Link 1</a>
<a href="#" data-bkgimg="link-2-bkg.jpg">Link 2</a>
</div>
I know this can be done with jQuery, but I prefer a vanilla JS solution if possible.