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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:19:42+00:00 2026-05-15T22:19:42+00:00

I am trying to work out how to expand all answers below a question

  • 0

I am trying to work out how to expand all answers below a question when an .allopener span is pressed. Users can currently expand each answer individually, but not all at once. Any tips would be much appreciated. There would be many items on a page.

The allopener span button will open up the remaining unhidden .text classes in this item to reveal the answers to the question as though someone has individually clicked expand on each. Note, when it is pressed for the first time, some, all or no answers may already be expanded. Additionally, when it is pressed again, all answers will be hidden. And if pressed another time, all answers will be expanded. If again, all hidden.

When, pressed, the background of each answer’s expand button will also change accordingly: ie turning on and off the class .highlightc on each individual expand button, as though toggling.

jquery:

$('.answeropener').click(function() {
$(this).next().toggle(); //unhide/hide the sibling text answer
$(this).toggleClass("highlightc"); //alternate the background of this button
return false;
});

$('.allopener').click(function() {
$(this).toggleClass("highlighti"); //toggles background of button
$(this). 
$(this). 
return false;
});

css:

.highlighti {background: #FFFFFF;}

.highlightc {border-right:1px solid #DCDCDC;}

.text {display:none;}

html:

<div class="item" id="question1">
<div class="tophead">How do you skin a cat?</div>
<div class="bottomhead">by Gerald, 1 hour ago <span class="allopener">open/close</span> <span>all answers below<span>
<div class="answers">

<div class="answer"><div class="answernumber">1</div><div class="answerhead">answer by Harold <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">this is my answer</div></div></div>

<div class="answer"><div class="answernumber">2</div><div class="answerhead">answer by Jesse <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">this is my answer too</div></div></div>

<div class="answer"><div class="answernumber">3</div><div class="answerhead">answer by Seth <span title="expand this comment" class="answeropener">expand</span><div style="display: block;" class="text">I don't know</div></div></div>

</div> <!--answers-->
</div> <!--bottomhead-->
</div> <!--item-->
  • 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-15T22:19:43+00:00Added an answer on May 15, 2026 at 10:19 pm

    You could do something like this:

    $('.answeropener').click(function() {
      $(this).toggleClass("highlightc").next().toggle();
      $('.allopener').toggleClass("highlighti", $('.text:hidden').length > 0);
      return false;
    });
    $('.allopener').click(function() {
      var any = $('.text:hidden').length > 0;
      $('.text').toggle(any).prev().toggleClass('highlightc', any);
      $(this).toggleClass("highlighti", any);
      return false;
    });
    

    You can give it a try here, apologies for the horrible, horrible colors used.

    What we’re doing is upon click of the all button we’re checking what the action should be (if there are any hidden, show them, if not hide them all). The in the click of each .answeropener we’re checking if it left ahy .text nodes hidden…so the styling of the .allopener is correct, e.g. then the last answer is expanded it’s highlighti class is removed, because on click it would be hiding them all…so it’s state now correctly reflects this.

    We’re able to keep this pretty short by using the .toggleClass(class, switch) overload, which lets you pass a boolean to tell it whether the class should be toggled on or off.


    Update for comments, here’s a version that’ll work per-question:

    $('.answeropener').click(function() {
        var q = $(this).closest('.item');
        $(this).toggleClass("highlightc").next().toggle();
        q.find('.allopener').toggleClass("highlighti", q.find('.text:hidden').length > 0);
        return false;
    });
    $('.allopener').click(function() {
        var q = $(this).closest('.item'), any = q.find('.text:hidden').length > 0;
        q.find('.text').toggle(any).prev().toggleClass('highlightc', any);
        $(this).toggleClass("highlighti", any);
        return false;
    });
    

    You can give it a try here

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

Sidebar

Related Questions

I am trying to work out why I can not access the nested function
I am trying to work out how I can insert the string End into
I'm trying to work out the ControlTemplate.Triggers in the Style below, and I haven't
I am trying to work out how to covert the script below from SQL
I am trying work out with MERGE statment to Insert / Update Dimension Table
Im trying to work out how to get the value from one setting in
I trying to work out what regex will match filenames in quotes. Eg. blah
i am trying to work out the following problem in Java (although it could
I am trying to work out the best practice for my problem. I have
I am trying to work out an IF statement and getting lost. I am

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.