My JS skills are failing me, and maybe also my Google skills. This is what I'm trying to do:
When an <li>
is hovered in the .first division, add an ".active" class to the <li>
in the .second division with the same ID. So if you hover over .first li#one, a class of .active would be added .second li#one.
Note: the IDs are dynamic and so can't be known in advance.
Here's what the html would look like:
<div class"first">
<ul>
<li id="one">Lorem</li>
<li id="two">Ipsum</li>
<li id="three">Dolor</li>
</ul>
</div>
<div class="second">
<ul>
<li id="one">Lorem</li>
<li id="two">Ipsum</li>
<li id="three">Dolor</li>
</ul>
</div>
I don't think there's a pure CSS solution, but of course that would be even better.
Anyone looking to do this with classes instead of IDs, here's the edited snippet from the below answer:
document.querySelectorAll("nav.primary li").forEach(li => {
li.addEventListener("mouseover", e => {
document.querySelectorAll(`.${e.target.classList}`)[1].classList.add("active");
});
li.addEventListener("mouseout", e => {
document.querySelectorAll(`.${e.target.classList}`)[1].classList.remove("active");
});
});