Is there a way to change the color of the <li>
element only when hovering over it, without affecting its parent or child elements?
Here is an example:
HTML:
<div id="tree">
<ul>
<li>apple</li>
<li>banana</li>
<li>mango
<ul>
<li>date</li>
<li>pear</li>
<li>fig</li>
</ul>
</li>
</ul>
CSS:
#tree > ul > li:hover {
background:brown;
}
#tree > ul > li:hover > ul >li{
background:white;
}
#tree > ul > li > ul > li:hover {
background:yellow;
}
https://jsfiddle.net/1v57nwg8/
If you have any suggestions using css, javascript, or jquery, they would be greatly appreciated.