Is there a way to manipulate an element when another element is being hovered over, with the two elements structured like this:
<div id="parent_element">
<div id="class-open-1"></div>
<div id="class-close-1"></div>
</div>
Or they might be structured like this:
<div id="parent_element">
<div id="div1">
<div id="class-open-1"></div>
</div>
</div>
<div id="parent_element"></div>
<div id="div2">
<div id="class-close-1"></div>
</div>
</div>
I have attempted a solution that works for the first case but not the second:
_style.innerHTML = ".class-open" + j + ":hover{ background-color: cyan; } .class-open-" + j + ":hover ~ .class-close-" + j + " { background-color: cyan; }
The value of 'j' changes, so I can only hover over classnames with the same 'j'.
This approach works for case one but not both cases. I also tried:
_style.innerHTML = ".class-open" + j + ":hover{ background-color: cyan; } .class-open-" + j + ":hover .class-close-" + j + " { background-color: cyan; }
However, this changes the background color without just hovering.
I am seeking a CSS or JavaScript-only solution that works for BOTH scenarios. Any suggestions?