The javascript to do this would be the following, thanks everyone for your
help.

$('.qa-list div').each(function(i) {
            $(this).children('.answer').slideUp();
        });

        $(".question").click(function(){
                var $this = $(this);
                if( $this.is('.question') ) {
                        $this.children('.answer').slideDown();
                        $this.removeClass('question');
                        $this.addClass('question-answer');
                        $this.siblings('.qa-list
div').children('.answer').slideUp();
                        $this.siblings('.qa-list
div').removeClass('question-answer');
                        $this.siblings('.qa-list div').addClass('question');
                }
                else {
                        $this.children('.answer').slideUp();
                        $this.removeClass('question-answer');
                        $this.addClass('question');
                }
                //return false;
        });

On Tue, Mar 3, 2009 at 3:45 PM, Brian Yanosik <byano...@gmail.com> wrote:

> So I have the following code and it works great. I am just curious how I
> can adapt it in order to only have 1 answer visible at one time. If once
> item is clicked, then on click of the other item, the last one automatically
> slides up. How would one go about doing this?
>
> JS:
>
> $(document).ready(function(){
>         $('.qa-list div').each(function(i) {
>             $(this).children('.answer').slideUp();
>         });
>         $(".question").click(function(){
>                 var $this = $(this);
>                 if( $this.is('.question') ) {
>                         $this.children('.answer').slideDown();
>                         $this.removeClass('question');
>                         $this.addClass('question-answer');
>                 }
>                 else {
>                         $this.children('.answer').slideUp();
>                         $this.removeClass('question-answer');
>                         $this.addClass('question');
>                 }
>                 //return false;
>         });
> });
>
> CODE:
>
> <div class="qa-list">
>    <div class="question">Question<br />
>    <span class="answer">this is the answer</span></div>
>    <div class="question">Question<br />
>    <span class="answer">this is the answer</span></div>
> </div>
>
> Thanks
> Brian
> ---------- Forwarded message ----------
> From: marc0047 <marc0...@gmail.com>
> Date: Tue, Mar 3, 2009 at 3:40 PM
> Subject: [jQuery] Re: slideToggle is jerky in Safari 3.2.1
> To: "jQuery (English)" <jquery-en@googlegroups.com>
>
>
>
> Looks like someone else had the same unresolved problem too:
>
>
> http://groups.google.com/group/jquery-en/browse_thread/thread/c929269adfd8ea99
>
> On Mar 3, 8:22 am, marc0047 <marc0...@gmail.com> wrote:
> > I am using slideToggle and it performs perfectly in FF, IE6&7, and the
> > new Safari 4. However, in Safari 3.2.1, the elements slide out, but it
> > starts of with a quick jerk and then slides.
> >
> > Has anyone else run into this problem and found a solution?
> >
> > Thanks!
>
>

Reply via email to