Try:

$(':checkbox').click(function(){
    $(this).parents('fieldset').next('fieldset').slideToggle();
});

.parent() has a limited scope and will return only the "parent"
elements. In the example you gave, fieldset is not a parent of
<input>, but an "ancestor". .parents() with the "s" at the end will do
an ancestral search, not just a parental search.

The .next() will return us the next sibling to the current element,
which in the example would be fieldset#id_2

So just to walk thru it real quickly:
$(this)    // The checkbox getting clicked
    .parents('fieldset')    // Fieldset#id_1, which contains the
checkbox
    .next('fieldset')    // Fieldset#id_2, which is the next fieldset
adjacent to Fieldset#id_1
    .slideToggle()    // Applied to the last element returned from the
jQuery chain, which is Fieldset#id_2

On Jan 5, 9:33 am, daweb <davideprevo...@gmail.com> wrote:
> Hi everybody and sorry about my English!
>
> This is my markup:
>
> <fieldset id="id_1">
> <dl class="campo-esteso">
> <dt>&nbsp;</dt>
> <dd>
> <input name="flag" type="checkbox" class="flag" id="flag" value="on"
> tabindex="1"  />
> <span class="opzionale">Toggle?!?!</span>
> </dd>
> </dl>
> </fieldset>
>
> <fieldset id="id_2"> // this fieldset is hidden
> Some input text type
> </fieldset>
>
> I have 3 similar checkbox field next. What about the best way to
> toggle the next fieldset element.
>
> I'd try this, but it doesn't works:
>
> $(':checkbox').click(function(){
> $(this).parent('fieldset').slideToggle();
>
> });
>
> Thank you all.

Reply via email to