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

  • SEARCH
  • Home
  • 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 7905155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:22:15+00:00 2026-06-03T10:22:15+00:00

I have seen many scripts for accordion on the internet, but haven’t found anything

  • 0

I have seen many scripts for accordion on the internet, but haven’t found anything which meets my needs. I want to make a plugin for accordion just like that which Facebook uses. It should work like this:

  1. Click to open and close.
  2. Add style class while open.
  3. Close upon an outside click. It should not close when click event is inside the accordion box.

Is there any way to achieve this? Please help if you know. I am new to jQuery…

Thanks in advance.

  • 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-06-03T10:22:17+00:00Added an answer on June 3, 2026 at 10:22 am

    No need for a plug-in when 15 lines of code will solve it: it’s about changing the order of the click events that trigger on a specific DOM element and on the window using setTimeout.

    var ShowingAccordion = false;
    
    $(document).ready(function () {
        
           $('.MyAccordionOpener').click(function () {
        
                 if ($(this).next('.MyAccordion').is(':visible') === false) {
    
                     ShowingAccordion = false;
                     $('.MyAccordion').hide(500);
                     $(this).next('.MyAccordion').addClass('SomeClass');
                     $(this).next('.MyAccordion').show(500);
                     setTimeout(function () { ShowingAccordion = true; }, 1);
                 }
           });
        
           $('.MyAccordion').click(function () {
            
                 ShowingAccordion = false;
                 //this is the line that solves your problem
                 setTimeout(function () { ShowingAccordion = true; }, 1);
           });
            
        
           $(document).click(function () { 
       
               if (ShowingAccordion === true) {     
    
                   $('.MyAccordion').hide(500);
                   ShowingAccordion = false;
               }    
           });
    });
    

    And here’s the demo

    If it does what you need then you can accept the answer and happy coding!

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

Sidebar

Related Questions

I have seen many php scripts in which you can cascade class method to
Ok I have seen many posts on this script. Which can be found..... http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
I have seen many question and applied their results but nothing happens I still
I have seen many answers for this type of question but its not related
I have seen many articles and Questions/Answers Regarding Lock Escalation but following things are
I have seen many answers on stackoverflow, but I didn't find an answer that
I have seen many souce codes but I have never ever come across a
I have seen many posts on this subject, but none have been answered, and
I have seen so many example of this problem but not as a list.
Hi all I have seen many articles on url rewriting but I didn't find

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.