jquery - Nested Li Elements Hover Alternate Background Color -
here's quick overview of problem. i've got list initial background color 1 this:
<ul> <li>item 1 <ul> <li>sub item 1 <ul> <li> sub sub item 1</li> <li>sub sub item 2</li> </ul> </li> <li>sub item 2</li> </ul> </li> <li>item 2</li> </ul>
what want that, first level items (item 1, item 2), when hovered upon, has background changed color two. when sub item 1,2 hovered upon, background color changed color 1. when sub sub item 1,2 hovered upon, changed color 2 , on nesting goes deeper. means alternate levels of nesting, background color alternates between 2 colors on hover goes deeper.
any idea how using jquery or css or both?
the problem having multiple hover events fired when hover on sub items. since sub part of parent element, parent technically getting hovered too. can fix wrapping text of each item in inline element span. each list item activates 1 hover event.
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> .odd {color:red;} .odd:hover, .odd:active{color:blue;} .even{color:blue;} .even:hover, .even:active{color:red;} </style> </head> <ul> <li><span class="odd">item 1</span> <ul> <li><span class="even">sub item 1</span> <ul> <li><span class="odd"> sub sub item 1</span></li> <li><span class="odd">sub sub item 2</span></li> </ul> </li> <li><span class="even">sub item 2</span></li> </ul> </li> <li><span class="odd">item 2</span></li> </ul> </html>
Comments
Post a Comment