Karl, that worked perfect. However, when I then click on the toggler
that has been changed back, the class on it is not being changed.
Here's the complete jQuery stuff, with the section you refined at the
bottom:

<script type="text/javascript">
        $(function() {
                $
('#ailment').find('.accContent').hide().end().find('.accToggler').click(function()
{
                        $(this).next().slideToggle();
                });
                 $(".accToggler").toggle(function() {
                                
$(this).removeClass("accToggler").addClass("accTogglerClose");
                         },function(){
                                
$(this).removeClass("accTogglerClose").addClass("accToggler");
                });
                $('#ailment p.close').click(function() {
                         $(this).parent().slideUp()
                .prev().removeClass('accTogglerClose').addClass('accToggler');
                });
        });
</script>

On May 25, 1:48 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> Hi Jared,
>
> It looks like there are a few ways you can tighten up your selectors,
> but the part that you're asking about could be changed from this ...
>
> > $('#ailment').find('.close').click(function() {
> >                    $('.accContent').slideUp();
> >                    $(this).prev('.accToggler').removeClass
> > ("accTogglerClose").addClass("accToggler");
> >            });
>
> to this ...
>
> $('#ailment p.close').click(function() {
>    $(this).parent().slideUp()
>     .prev().removeClass('accTogglerClose').addClass('accToggler');
>
> });
>
> So, you're first traversing from the clicked element to its parent
> and sliding it up; then, you're traversing to the previous element --
> in relation to the parent -- and swapping the classes on it.
>
> Hope that helps.
>
> --Karl
> _________________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On May 25, 2007, at 11:24 AM, [EMAIL PROTECTED] wrote:
>
>
>
> > I'm trying to have a "close" link in a div that is expanded by click
> > on an h3 that is the toggler. The trick is, I need that close click to
> > then change the class of the h3 that preceeds it, not all h3s on the
> > page.
>
> > <h3 class="accToggler ">Title</h3>
> > <div class="accContent">
> >     <p>Content</p>
> >     <p class="close">Close</p>
> > </div>
>
> > So far my script looks like this:
>
> > <script type="text/javascript">
> >    $(function() {
> >            $
> > ('#ailment').find('.accContent').hide().end().find
> > ('.accToggler').click(function()
> > {
> >                    $(this).next().slideToggle();
> >            });
> >             $(".accToggler").toggle(function() {
> >                            
> > $(this).removeClass("accToggler").addClass("accTogglerClose");
> >                     },function(){
> >                            
> > $(this).removeClass("accTogglerClose").addClass("accToggler");
> >            });
> >            $('#ailment').find('.close').click(function() {
> >                    $('.accContent').slideUp();
> >                    $
> > (this).prev('.accToggler').removeClass("accTogglerClose").addClass
> > ("accToggler");
> >            });
> >    });
> > </script>
>
> > Thanks in advance.

Reply via email to