Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7704335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:39:32+00:00 2026-05-31T23:39:32+00:00

I have a button which when toggled displays/hides a div (‘.reportOptions’), this works perfectly

  • 0

I have a button which when toggled displays/hides a div (‘.reportOptions’), this works perfectly 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 away from it by doing the following

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

the problem I have with the last function is that if it is performed I must double click the resuestOptions button in order to display the div again.

What I want to know is if there is any way in which you can reset the toggle state without having to change the toggle function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:39:33+00:00Added an answer on May 31, 2026 at 11:39 pm

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

    You may also want to take a moment to read through it further as there are show() and hide() methods. You should not be using css(‘display’,’none’) to show and hide elements as the show and hide methods will handle all of that for you and it’s much less confusing when you read your code.

    I think you may have overthought this situation a bit. Try this instead:

    $('.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();
    });
    

    Basically you’re binding a click function to the button that shows the div and hides the button and a click function to the document which hides the div and shows the button. The clicks on the button and the div stop propagation (which is what you were missing in the button before) so that the document click handler doesn’t fire when those elements were clicked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button which is in update panel. When I click on button
I have a button which creates a div. Once clicked I would like to
I have this button which is not working correctly for hold button for a
On my website, I have a button which when clicked displays a feedback form
I currently have a button triggering this: def spam(self,event): t = workingthread() t.start() Which
In this example (which is working) on click of a button the section is
I have a Main-Activity which displays several spinners. With a Toggle-Button in the Main-Activity
I'm using Javascript/Jquery to have a button toggle which div is displayed in the
The code below will show / hide a div on click. It works perfectly
I have a panel which is toggled visible/invisible on clicking a button. Say the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.