shana
shana

Reputation: 27

Return Class after Remove?

Is it possible to return a class immediately after it's removed by hover? So when you're no longer hovering, the class returns?

$("#all").hover(function() {
 $('.morenav').removeClass('active');
$(this).closest(".morenav").toggleClass("hovered")});

 $("#all").click(function() {

$(this).closest(".morenav").toggleClass("active") });  

The way it's set up now, the active class doesn't come back when the element is no longer hovered. Can anyone help me out?

Upvotes: 0

Views: 92

Answers (2)

Adrift
Adrift

Reputation: 59819

$("#all").hover(function() {
    $('.morenav').removeClass('active');
    $(this).closest(".morenav").toggleClass("hovered")
    }, function() {
        $('.morenav').addClass('active');
    });
$("#all").click(function() {
    $(this).closest(".morenav").toggleClass("active") 
});  

Upvotes: 1

Navneil Naicker
Navneil Naicker

Reputation: 3691

It is clearly stated in jQuery documentation. You can try something like this. Hope it helps.

$("#all").hover(function() {
    $('.morenav').removeClass('active');
    $(this).closest(".morenav").toggleClass("hovered")
    }, function() {
        $('.morenav').addClass('active');
    });
$("#all").click(function() {
    $(this).closest(".morenav").toggleClass("active") 
});

Upvotes: 0

Related Questions