Reputation: 27
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
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
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