0

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 .

jsfiddle Demo

$(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');
});
Rajan Kumar
  • 63
  • 1
  • 11
  • 1
    Possible duplicate of [jQuery: trigger a hover event from another element](http://stackoverflow.com/questions/13325519/jquery-trigger-a-hover-event-from-another-element) – oguzhancerit Oct 17 '15 at 23:22
  • Why you don't add a class to the menu you want to show when you click on collapse button? – diegorp Oct 17 '15 at 23:24

2 Answers2

1

You must add class, to rember your condition. I am change your example jsfiddle Demo

$(document).on('click', '.btn2', function () {
$('.imFirst').addClass('active');

});

Piotr Kazuś
  • 346
  • 2
  • 12
1

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.

jmancherje
  • 6,439
  • 8
  • 36
  • 56