I'm doing a CSS drop down menu but I think I might have done it wrong.
The menu works but when I roll over the button with the drop down underneath it(Two in the exmaple) and move on to the drop down menu the button (Two) loses it's background color.
How can I keep the nav button (Two in the example) selected with the background color when I have rolled on to the drop down menu.
Also is this the best way to do this? Can I do it better?
Here we go, after your META tag, add the following code:
Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("ul ul li").hover(
function () { $(this).parent().parent().css('background', '#eee'); },
function () { $(this).parent().parent().css('background', '#ffffff'); } ); });
</script>
That's it.
Basically, you first add jQuery hosted on Google.
Then, inside "on document ready" (after site has loaded)
You say:
go into every "ul ul li" on the page,
and highlight 2nd parent of it on mouse over
and unhighlight 2nd parent of it on mouse out
$("ul ul li") is the jQuery selector that selects your sub menu
hover() is the jQuery function that works with mouse over and mouse out events on the selected element. So you get
Code:
$("ul ul li").hover(...
Then you provide 2 javascript functions for mouse in and mouse out,
inside those functions put what you want to do each time.
jQuery, yet again to the rescue.
Inside those two functions I use the following code:
Bookmarks