JQuery - reset switch state

I have a button that when switching shows / hides div ('.reportOptions'), this works fine.

$('.reportOptions').click(function(e){ 
   e.stopPropagation();
});


$('.requestOptions').toggle(
   function(){
      $(this).parent().find('.reportOptions').css('display','block');   //show request options
   },function(){
      $('.reportOptions').css('display','none');    //hide all request oprtions menus
   }
);

the same div can also be hidden by clicking on it by doing the following

$(document).click(function(){
   $('.reportOptions').css('display','none');
   $('.requestOptions').toggle(even);
});

The problem with the last function is that if it is executed, I have to double-click the resuestOptions button to display the div again.

I want to know if there is a way that you can reset switch the state without having to change the switch function.

+5
source share
2 answers

Take a look at the documentation for the jQuery toggle method: http://api.jquery.com/toggle/

, , show() hide(). css ('display', 'none'), , show hide , , .

, , , . :

$('.reportOptions').click(function(e){ 
   e.stopPropagation();
});


$('.requestOptions').click(
   function(e){
      $(this).parent().find('.reportOptions').show();   //show request options
      $('.requestOptions').hide();    //hide all request oprtions menus
      e.stopPropagation();
   }
);


$(document).click(function(){
   $('.reportOptions').hide();
   $('.requestOptions').show();
});

, div, , div . ( , ), .

0

, CSS, ( CSS). , .

0

All Articles