>I have two jQuery books and scant coverage of $(this) between them. I
>need to know if $(this) has parents, children and siblings, and if so
>how to access them. Here's why...
>
>I have a page with six one-line forms on it. I put the forms in divs
>and hide the divs on page load based on the class of the divs. Each
>div has an immediate sibling <a> that will toggle the form on a click.
>It works great if I write a separate function for each div, but I want
>to combine them into one function, bind that function to all of the
><a> by ID and use $(this) to know which is which when the event fires.
>No problem, except that I need to fire the event on the next sibling,
>not on the element I get with $(this). I've tried using the + sign in
>several ways, but nothing has worked so far. How do I select the
>parent, child or sibling of $(this)?

This would attach the behavior to any link element with the class of
"formToggle":

$("a.formToggle").click(function (e){
        // this = anchor tag that was just clicked
        $(this).prev().toggle();
});

-Dan

Reply via email to