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

The Archive Base Latest Questions

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

I am creating a simple page with questions and answers. This is how it

  • 0

I am creating a simple page with questions and answers.
This is how it looks:

SECTION > Question > Answer

And this keeps on repeating with different sections, Each section has multiple questions and each question has an answer. By default everything is set to display:none. Now when someone clicks on any of the section, the related set of questions should showup, and when someone clicks on the question, it;s answer should show up.

Only one section should be open at a time.

I kind of figured it would require parent(), child(), each() functions but I don’t know how and where to use them 🙁

I have previously used javascript and used to do it via ID basis, but since I’m using jQuery, I thought I’d rewrite the page using classes as .section, .question and .answer

Here is a the simple fiddle page where I have created li elements : http://jsfiddle.net/DKMJH/2/

  • 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-25T22:29:19+00:00Added an answer on May 25, 2026 at 10:29 pm

    Your HTML is invalid, <li> elements don’t nest like that so the browser will probably try to fix it up and what sort of selector you want for the next question or answer depends on how the browser decides to mangle your HTML. You probably want this HTML:

    <ul>
        <li class="section">Section One</li>
        <li class="question">This is a question</li>
        <li class="answer">This is an answer</li>
        <li class="section">Section Two</li>
        <li class="question">This is another question</li>
        <li class="answer">This is another answer</li>
    </ul>
    

    Now that we have valid HTML, we’ll know what the final structure really is and you can use next to find the appropriate single element to open:

    $('.section').click(function() {
        $(this).next('.question').slideToggle(500);
    });
    $('.question').click(function() {
        $(this).next('.answer').slideToggle(500);
    });
    

    You also spelled cursor wrong in your CSS but that won’t have any effect on your jQuery.

    Fix fiddle: http://jsfiddle.net/ambiguous/jcnMa/

    ryudice was in first and got to the heart of the matter, I just needed more space than a comment to deal with the broken HTML issue. Using next only works because the browser is restructuring your HTML into a single unordered list.

    If you only want one question open at a time, then close the other ones:

    $('.section').click(function() {
        var $others = $('.question:visible').not(this);
        $others.next('.answer').hide();
        $others.slideToggle(500);
        $(this).next('.question').slideToggle(500);
    });
    

    Demo: http://jsfiddle.net/ambiguous/jcnMa/1/

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

Sidebar

Related Questions

When creating a simple Flex 4.6 App, where the creationComplete-handler looks like this: protected
I'm trying to make this simple code of creating 3 multiple-choice question out of
This question undoubtedly has a simple answer however I have not been able to
I am trying to imitate this tutorial about creating a simple Apple-themed breadcrumb found
I browsed through the site for awhile to find an answer to this question
I'm creating a seemingly simple dojo 1.8 web page which contains an app layout
I'm creating simple payment form that allows users to select from several different gateways
This should be simple but nothing's working: Question How do you set the height
Apologies if this is a simple question, but I turn to the wisdom of
I'm creating simple example on JSF. It's small Login application. My problem is duplicate

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.