> I have a form that is repeated through out the page by the backend, > which I have no control over. > <form action=""> > <textarea class="your_comment" rows="10" cols="70"></textarea> > <a href="#" class="comment_form_cancel">Cancel</a> > </form> > > I want to attach an event to the link to clear the textarea. > $(".comment_form_cancel").live("click", function(event) { > $(".your_comment").val(''); > event.preventDefault(); > > }); > > This method would be attached to all instances of the form. However, > I would like only the form the user is currently working on to trigger > the method. For example, if there are 3 forms, I click the cancel > link on the 3rd form, the clearing should only happen on the 3rd form, > not all forms. Is there a way to do this?
This should work: $(".comment_form_cancel").live("click", function(event) { $(this).prev(".your_comment").val(''); event.preventDefault(); });