Ah, you're missing the var keyword. Compare your eachForm = $(this);
to Dave Methvin's var $form = $(this); That's why you were always getting the last form element. No var keyword means global scope means no closure. - Richard On Thu, Sep 18, 2008 at 9:36 PM, Ariel Barreiro <[EMAIL PROTECTED]> wrote: > > I have a question, is there a way to reference the context in a way > such as $(this)? > > for example, let say I have this (using general selectors) > > $('.forms').each(function(i) { > // I want to iterate over all forms > // here $(this) is each form > $(':input', $(this)).change(function(){ > // Here I want to do something with the input element as well as > with the form element, but $(this) would be the input element, can I > do something to reference to the form element? > }); > }); > > I am trying this but of course it doesn't work as eachForm ends up > being just the latest form > > $('.forms').each(function(i) { > // I want to iterate over all forms > eachForm = $(this); > $(':input', $(this)).change(function(){ > doSomething($(this),eachForm); > }); > }); > > Thanks for any light in this, >