Jump to content

Don't Automatically Hover on new navigated page


FishSword

Recommended Posts

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>
Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.