modifying css with jquery

I have a ul list and below im using jquery to find out if the user is hovering sub menus under about us and if yes set some css on hover. This does change the background color to green but when i hover off the green doesnt go away?

JQUERY

$('ul > li > ul > li a').hover(
    function(){
        var whatami = $(this).parents('li').eq(1).find('a[title]:first').attr('title');
        console.log(whatami);
        if (whatami == 'About Us') {
            //alert(whatami);
            $('.white ul.mega-menu li .sub-container.non-mega li a:hover').css({"background-color":"green"});

        }
    },
    function(){
    });

Answers


in jQuery the :hover is just an element selector, it's not the same as CSS a:hover. Trying something like:

$('.white ul.mega-menu li .sub-container.non-mega li a').hover(
    function () {
        $(this).css({"background-color":"green"});
    },
    function () {
        $(this).css({"background-color":"none"});
    }
); ‚Äč

The way hover works is that the first function is executed when the mouse enters and the 2nd is executed when the mouse leaves. You have nothing in the 2nd function, so that means nothing will happen when the mouse leaves. You need to do whatever you want to do in the 2nd function:

$('ul > li > ul > li a').hover(
function(){
    // make it green
},
function(){
    // CHANGE IT BACK HERE
});

Need Your Help

What is wrong with this MySQL/Java prepared statement syntax?

java mysql sql web-applications jdbc

I have a small program that I have built to cycle a list of passwords from a database, hash them, and update the database with the hashed password. I have already altered the column length so as to...

Adding\Removing from ListView but not reflecting in UI

wpf listview binding

I have two List<ColumnClass>. one for left side listview and another for right side list view. these listviews are in a pop up box. I am modifying the List of both the Listviews and again ass...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.