I want to update the background image of a parent div that contains a series of ul li elements. Here is the HTML code I am working with:
<section class="list" id="services">
<div class="row">
<ul>
<li><a href="automation.html" class="list-item"> <span class="desc">About the page</span><span class="title">Automation</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="research.html" class="list-item"> <span class="desc">About the page</span><span class="title">R&D</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="ui.html" class="list-item"> <span class="desc">About the page</span><span class="title">UI/UX</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="webdev.html" class="list-item"> <span class="desc">About the page</span><span class="title">Web Development</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="mobile.html" class="list-item"> <span class="desc">About the page</span><span class="title">Mobile App Development</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="market.html" class="list-item"> <span class="desc">About the page</span><span class="title">Digital Marketing</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="gaming.html" class="list-item"> <span class="desc">About the page</span><span class="title">Gaming</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="business.html" class="list-item"> <span class="desc">About the page</span><span class="title">Our Business</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="faq.html" class="list-item"> <span class="desc">About the page</span><span class="title">FAQ</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
<li><a href="about.html" class="list-item"> <span class="desc">About the page</span><span class="title">About Us</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
</ul>
</div>
</section>
The "list" class features a background image. My goal is to change this background image when a user hovers over an li a element. Here is what I have attempted:
.list ul li a:hover .list {background-image: url('some.jpg');
This approach did not work as intended. Additionally, I aim to have the background image change based on the category being hovered over. For example, hovering over the automation list item should load an appropriate background image. I also tried the following method:
HTML
<li><a href="automation.html" class="list-item" data-class="someclass"> <span class="desc">About the page</span><span class="title">Automation</span><span class="nav-icon"><i class="fa fa-chevron-right"></i></span></a></li>
JS
<script> var el = document.getElementById("services");
el.addEventListener("mouseover", services);
function services(e) {
e.currentTarget.className = e.target.getAttribute('data-class');
}
</script>
However, this script seems to be causing issues by replacing the "list" class with a "null" class instead. Can anyone advise on what might be going wrong? I'm new to JavaScript and eager to learn. Any guidance would be greatly appreciated.