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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:46:20+00:00 2026-06-02T00:46:20+00:00

I have a working toggle function that expands and collapses but my list when

  • 0

I have a working toggle function that expands and collapses but my list when expanded is very long and I wanted to put a “Close” link at the bottom to enable collapse so my users don’t have to scroll to top to click and collapse. Any ideas how I can modify this code to expand it’s functionality for my purposes?

<script language="javascript">
$(function(){
$(".formname").toggle(function(){
var id=$(this).attr('id');
$("#form"+id).fadeIn('slow');
},function(){
var id=$(this).attr('id');
$("#form"+id).fadeOut('slow');
}); 
});
</script>

my html looks like:

<ul>
<li><a href="#" id="formxyz" class="formname">My Expanding/Collapsing Data</a></li>
<div style="display:none;">
<ul>
<li>Content</li>
</ul>
</div>
</ul>

if I insert the same link li at the bottom before the closing ul the user has to click it twice to collapse. I’d prefer a single click solution.

<ul>
<li><a href="#" id="formxyz" class="formname">My Expanding/Collapsing Data</a></li>
<div style="display:none;">
<ul>
<li>Content</li>
<li><a href="#" id="formxyz" class="formname">Close</a></li>
</ul>
</div>
</ul>
  • 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-02T00:46:22+00:00Added an answer on June 2, 2026 at 12:46 am

    If you use toggle() event on formxyz, the new close action will break the original rule, therefore sometimes you have to click formxyz twice to show content.

    So use click() event with fadeToggle() action on formxyz. It will show content while it’s hiding.

    Then add a class on all “close”, use parents method to find it’s parents div (it should be the content div), then hide it.

    The html:

     <div style="background-color: gray">
      <li><a href="#" id="xyz" class="formname">My Expanding/Collapsing Data</a></li>
      <div id="formxyz" class="content" style="display:none">
        <ul>
          <li>Content</li>
          <li><a href="#" class="closeform">Close</a></li>
        </ul>
      </div>​
    </div>
    

    The js file:

    $(function(){
      $(".formname").click(function(){
        var id=$(this).attr('id');
        $("#form"+id).fadeToggle('slow').focus();
      }); 
    
      $(".closeform").click(function(){
        $(this).parents("div.content").fadeOut('slow');
      });
    });
    

    ​

    OR Check emulate code on jsFiddle. It’s executable.

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

Sidebar

Related Questions

I have try with toggle function in jquyer but its not working for multiple
i have a toggle function which i have working fine, only i cant get
I'm working in Adobe AIR, and I have a list of divs that show
I have a show/hide toggle working well in multiple instances (thanks to help here
I have working registration script the only problem is that i do not know
Have been working on this question for a couple hours and have come close
Hi Sorry for this noob question but here goes...i have a working slidetoggle on
I have a toggle event that is being used to show and hide a
I have a JQUERY AJAX post function that will work if there is one
I've had this working fine: $('#RCH'+r).on('click',function(e){$('#RSC'+r).find('.rct,.rcp').toggle();}); At the end of all the toggles, though,

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.