Select next element of a given class

Posted by kevinb92 on Stack Overflow See other posts from Stack Overflow or by kevinb92
Published on 2010-06-15T09:02:06Z Indexed on 2010/06/15 10:02 UTC
Read the original article Hit count: 202

Filed under:
|

Hello,

I want to hide and show some form in my page.

For each form theres a link, and i want that, when i click on this link, it hide and show the nearest form of the link.

My code looks like this :

    $$('.flagLink').each(function(s){
        $(s).observe('click', function(event) {
            // here i want to hide and show the nearest form
        });
    });

I've tried this :

    $$('.flagLink').each(function(s){
        $(s).observe('click', function(event) {
            $(s).next('form').toggle();
        });
    });

It works but, i would like to be more precise like :

    $$('.flagLink').each(function(s){
        $(s).observe('click', function(event) {
            $(s).next('.flagForm').toggle();
        });
    });

but the .flagForm selector doesnt work.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about prototype