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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:56:15+00:00 2026-05-22T18:56:15+00:00

ok, so I have a structure like two divs. On the left side div

  • 0

ok, so I have a structure like two divs. On the left side div I have a list of 10 questions, and on the right hand side I want to populate the answers for the same. On clicking the question1 on the left hand side the answer should display in the right hand side. On clicking the second question the answer for second should display, hiding all the answers. so what would be the ideal way to do it in jquery.
I wrote something like;

$("document").ready(function() {
   $("#idQ1").click(function() {
     $("#ansQ1").css("display","block");
    $("#ansQ1,#ansQ2,#ansQ3,#ansQ4,#ansQ5,.......#ansQ10").css("display","none");
})
}) 

but I dont think this code is good. can somebody guide as to how you would do this using loops or functions

  • 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-22T18:56:16+00:00Added an answer on May 22, 2026 at 6:56 pm

    The other answers are dead on with using classes to write an efficient script for this

    I’ve created my own example here that uses anchor tags for the questions with an href set to the id of an answer element.

    example here: http://jsfiddle.net/pxfunc/zEwUB/

    HTML:

    <div id="container">
        <div id="questions">
            <a href="#answer1">Question 1?</a>
            <a href="#answer2">Question 2?</a>
            <a href="#answer3">Question 3?</a>
        </div>
        <div id="answers">
            <p id="defaultText">Click a question to show the answer here!</p>
            <p id="answer1" class="answer">Answer 1!</p>
            <p id="answer2" class="answer">Answer 2!</p>
            <p id="answer3" class="answer">Answer 3!</p>
        </div>
    </div>
    

    jQuery:

    $('#questions a').click(function(e) {
        e.preventDefault(); // prevents the link from changing the URL
    
        $('#answers p').hide(); // hide all answers
        $($(this).attr('href')).show(); // get href attribute to show answer
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html structure like this: <div class=one> <div id=two> <h2>Any</h2> <h4>Any</h4> </div>
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
For example, I have a directory structure like this: my_stuff classes one two more
I have a HTML structure like follows <div id=answer-1> <a class=edit></a> </div> <div id=answer-2>
Let's say we have a data structure like this: var sequences = new List<Tuple<int,
I have a typical N-M relationship structure like this: two independent tables: Table Client:
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a structure like this.... UITableViewController -> UITableViewCell -> UIView I need the
I have a structure like the following: <form> <input type=text /> <input type=text />
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five

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.