FishSword Posted August 3, 2014 Share Posted August 3, 2014 I have the following menu that changes to red if each of the menu items are hovered over. This menu shows on every page of my website. I have the following problem: If a user was to click a menu item (e.g. Menu 2), the page will navigation to the page set in the a tag (i.e page2.html) If the user was to leave there mouse in the same position as it was in before the menu item was clicked (i.e. over the selected menu item), then the menu would automatically change to red again on the new page, as the jQuery hover code below will be activated. Is there a way to stop this behaviour? Ideally I want users to have to mouse off of the menu item and then on it again before the menu item changes to red if the users mouse is still over the selected menu item after clicking one of the menu links. <script type="text/javascript"> $(document).ready(function() { $('li').hover(function() { $(this).css('background', 'red'); }, function() { $(this).css('background', 'none'); }) }) </script> <ul> <li><a href="page1.html">Menu 1</a></li> <li><a href="page2.html">Menu 2</a></li> <li><a href="page3.html">Menu 3</a></li> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/290250-dont-automatically-hover-on-new-navigated-page/ Share on other sites More sharing options...
CroNiX Posted August 3, 2014 Share Posted August 3, 2014 (edited) Probably just set all of your li to background none before your hover code. Edited August 3, 2014 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/290250-dont-automatically-hover-on-new-navigated-page/#findComment-1486751 Share on other sites More sharing options...
Andy11548 Posted August 25, 2014 Share Posted August 25, 2014 Hello, Are you trying to make it so that while the mouse is on the navigation button the background of the button changes to red, once the mouse is removed, it should change back to it's default colour? Sorry, I didn't understand your query. Quote Link to comment https://forums.phpfreaks.com/topic/290250-dont-automatically-hover-on-new-navigated-page/#findComment-1488858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.