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 8149515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:52:05+00:00 2026-06-06T14:52:05+00:00

I found this jQuery plugin online that shows and hides divs. It’s perfect for

  • 0

I found this jQuery plugin online that shows and hides divs. It’s perfect for my site except for one factor. When you click on a heading, the corresponding div appears. But that div won’t disappear until you click another heading. How do I tweak the code below so that if you click on the same heading a second time, the div hides again?

(function ($) {
$.fn.showHide = function (options) {

//default vars for the plugin
    var defaults = {
        speed: 1000,
        easing: '',
        changeText: 0,
        showText: 'Show',
        hideText: 'Hide'

    };
    var options = $.extend(defaults, options);

    $(this).click(function () {
// optionally add the class .toggleDiv to each div you want to automatically close
                  $('.toggleDiv').slideUp(options.speed, options.easing);
         // this var stores which button you've clicked
         var toggleClick = $(this);
         // this reads the rel attribute of the button to determine which div id to toggle
         var toggleDiv = $(this).attr('rel');
         // here we toggle show/hide the correct div at the right speed and using which easing effect
         $(toggleDiv).slideToggle(options.speed, options.easing, function() {
         // this only fires once the animation is completed
         if(options.changeText==1){
         $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
         }
          });

      return false;

    });

};
})(jQuery);
  • 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-06T14:52:07+00:00Added an answer on June 6, 2026 at 2:52 pm

    Try this:

    $(this).click(function() {
        var toggleClick = $(this);
        var toggleDiv = $(this).attr('rel');
        var isDivVisible = $(toggleDiv).is(":visible");
        $('.toggleDiv').slideUp(options.speed, options.easing);
    
        if (!isDivVisible) {
            $(toggleDiv).slideToggle(options.speed, options.easing, function() {
                if (options.changeText == 1) {
                    $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
                }
            });
        }
        return false;
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am searching for a password strenght checking jQuery plugin. i found this one:
im using this youtube api jquery plugin that i found(the code is located here):
I found this jquery plugin which does exactly what I need, but I want
I found this content expand/collapse jQuery plugin. I want to add fade-in effect to
I found this great Tablesorter plugin for jQuery but I can't make it work
I found this simple jquery plugin from jQuery Set Cursor Position in Text Area
This is a 'hack' that enables the colorbox jQuery plugin to work with the
We found a JQuery plugin called FixedTable that is used to add scroll bars
I found this tutorial which uses jQuery and validation plugin to validate form input.
I'm now writing my first jQuery Plugin and i found this blog post about

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.