Grow your CSS skills. Land your dream job.

[Solved] Jquery – add class on hover

  • # January 8, 2014 at 8:16 am

    Hi, how can i add a class to the element when mouse get on hover it and that element keep class until mouse goes on another element then remove added class and add it to other on hovered element ?

    sorry for my bad eng, i hope you understand my mean…

    # January 8, 2014 at 8:38 am

    http://codepen.io/alenabdula/pen/fjuGn

    Hope that helps.

    # January 8, 2014 at 8:51 am

    Thank you, it’s work perfectly but when mouse out added class removed!
    i want keep class until mouse goes on another li, if not don’t remove added class…

    # January 8, 2014 at 9:24 am

    i want keep class until mouse goes on another li, if not don’t remove added class…

    That would not be appropriate…you should not apply changes on hover that you want to remain in place when the hover is removed.

    Can you explain why this would be required?

    # January 8, 2014 at 9:25 am

    i find it:

    var myMenu = $('.menu li');
    
    myMenu.mouseenter(function () {
        myMenu.filter('.is_hovered').removeClass("is_hovered");
        $(this).addClass("is_hovered");
    });
    

    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".