I am unable to get the background color of the li
tags to change to red when my mouse hovers over them.
excerpt from javascript.info
Can use pseudo-classes as well: Pseudo-classes in the CSS selector like :hover and :active are also supported. For instance, document.querySelectorAll(':hover') will return the collection with elements that the pointer is over now (in nesting order: from the outermost to the most nested one).
let hover = document.querySelectorAll('li:hover');
for (let elem of hover) {
elem.style.background = 'red';
};
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
</ul>
</div>