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

  • Home
  • SEARCH
  • 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 7985927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:41:56+00:00 2026-06-04T11:41:56+00:00

So i have to come up with some kind of mini script that behaves

  • 0

So i have to come up with some kind of mini script that behaves like this,

click a sentence, or a question, and the answer drops(slide down). click it again and it slides up etc..

simple enough….

Now im a noob so for example, if i have 1 questions, then of course ill write something like this:

css:

.answer { display:none }

js/jQ:

var question = $('.question');
var answer = $('.answer');

question.click( function(){
    answer.slideToggle(500);    
});

etc, but so now if i have say, 5 questions then ill have to create 5 more variables(or call em directly with jq) and etc etc…long story short, itll be code for EVERY question/answer set which will get unwieldy fast

im trying to write something a bit smarter (and much less code) so to test my logic i try this:

question.click( function(){
    if($(this).parent().hasClass('open')){
        $(this).parent().removeClass('open');
        alert("its open");  
    } else {
        alert("its not open");
        $(this).parent().addClass('open');

    }
});

now when i try this, it works. when its open it alerts open and removes the class open so on its next click, its not open and alerts me so aswell…so small test working.

So naturally this means i SHOULD be able to add SOME kind of animate/slide code to get me rolling and it SHOULD work but either A, it doesnt work, or B, it opens ALL the answers at the same time.

ive tried

question.click( function(){
    if($(this).parent().hasClass('open')){
        $(this).parent().removeClass('open');
        //alert("its open");
        answer.slideUp(500);    
    } else {
        //alert("its not open");
        $(this).parent().addClass('open');

        answer.slideDown(500);
    }
});

and this one opens ALL the answers at the same time no matter what question i click on.

i figured, let me add a “this” to the answer line to localize the event…maybe something like.

$(this).answer.slideDown(500);

but this plainly just doesnt work.

Ive also tried something like $(this).find('answer').slideUp(500);

I KNOW im close lol. Any tips/links, explanations etc ill gladly appreciate.

  • 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-04T11:41:59+00:00Added an answer on June 4, 2026 at 11:41 am

    http://jsfiddle.net/7eHzz/

    <div class="question">
       q1
        <div class="answer">
          a1
        </div>
    </div>
    
    
    
    var question = $('.question');
    var answer = $('.answer');
    
    question.click( function(){
        $(".answer",$(this)).slideToggle(500);    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stumped by this one. I have tried several angles and some come
I have some colors that seem to come from a Delphi TColor variable (e.g
i'm currently constructing some kind of mini-framework for a project, and come up with
I have some Kind of Question about FFT (Actually I believe it's more about
I have seen some examples that show that Firefox supports some kind of JavaScript
Is it possible to have some kind of type converter that allows Sync Framework
I seem to have some kind of multithreading bug in my code that makes
A problem that has frequently come up in my career is I have some
While making my program i have come across this requirement that i have to
I come back here because I have some kind of problem. (I posted 2

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.