Reputation: 63
I have fixed sidebar navigation bar, it works on hover but I want to open first menu by clicking on collapse button. similar working like hover on menu 1. I have already tried following methods .
$(document).on('click', '.btn1', function () {
console.log('btn 1');
//$('.imFirst a').trigger('mouseenter');
//$('.imFirst a').trigger('mouseover');
//$('.imFirst a').trigger('hover');
$('.imFirst a ').mouseenter()
//$('.imFirst a ').mouseover()
$('.imFirst a').toggleClass('hover');
});
$(document).on('click', '.btn2', function () {
console.log('btn 2');
//$('.imFirst ').trigger('mouseenter');
//$('.imFirst ').trigger('hover');
//$('.imFirst ').trigger('mouseover');
$('.imFirst ').mouseenter();
//$('.imFirst ').mouseover();
$('.imFirst ').toggleClass('hover');
});
Upvotes: 0
Views: 68
Reputation: 6633
Like the previous answer I think your best bet is to add a class that is toggled when you click on the toggle button. The only difference with the previous answer is in the jsfiddle demo it works much better to add
$('.imFirst').toggleClass('active');
so you are able to close the menu after opening it.
My rep is too low to add this as a comment.
Upvotes: 1
Reputation: 344
You must add class, to rember your condition. I am change your example jsfiddle Demo
$(document).on('click', '.btn2', function () {
$('.imFirst').addClass('active');
});
Upvotes: 1