0

I'm using this form plugin

But for the life of me, I can't figure out how to do much DOM manipulation after the form has been submitted.

$('.save-form').each(function() { $(this).ajaxForm({ beforeSubmit: function() { // }, success: function(data) { // } }); }); 

I've tried $(this).find('div').hide(); but to no avail.

HTML:

<form method="post" class="save-form"> <!-- inputs are here --> <div>I want to hide this as well as the parent, "save-form".</div> </form> <form method="post" class="save-form"> <!-- inputs are here --> <div>I want to hide this as well as the parent, "save-form".</div> </form> <form method="post" class="save-form"> <!-- inputs are here --> <div>I want to hide this as well as the parent, "save-form".</div> </form> 

Yes, I have more than one instance of "save-form"

1
  • You could just use $(".save-form") rather than the longhand selector you've used. Commented Jun 11, 2012 at 9:05

4 Answers 4

3

Do:

$('[class=save-form]').each(function() { $(this).ajaxForm({ beforeSubmit: function() { // }, success: function(data) { $('[class=save-form]').hide(); } }); }); 

Notice that it will hide what is in the wrapped set $('[class=save-form]'). You may want to adjust your selector as per your needs.


By the way, you can use:

$('.save-form') 

Instead of:

$('[class=save-form]') 
Sign up to request clarification or add additional context in comments.

6 Comments

That will hide all elements that match [class=save-form] when one successfully completes.
@JamesAllardice: Yeah was writing that (before your comment seen), updated.
Oops, I asked my question wrong. I have updated my post to include what I'm trying to hide.
@Aaron:For that you can use $('.save-form > div').hide(); for immediate div children or $('.save-form div').hide(); for divs at any depth. Notice that as you said this will hide divs only.
@Aaron: You want to hide all forms and everything inside them right ?
|
2

each accepts two params. Use them.

$('[class=save-form]').each(function(index, form) { $(this).ajaxForm({ beforeSubmit: function() { // }, success: function(data) { $(form).find('div').hide(); } }); }); 

1 Comment

In this case form will be a DOM node, not a jQuery object. You will need to do $(form).hide();. But +1 for remembering that extra argument which I always forget!
2

If you store a reference to this before calling ajaxForm you will be able to use that inside the event handlers:

$('[class=save-form]').each(function() { var form = $(this); $(this).ajaxForm({ beforeSubmit: function() { // }, success: function(data) { form.hide(); } }); }); 

1 Comment

It will still hide all forms since it is inside each
0

Not sure if this is the answer but could you wrap it around a div and hide that? Seems easiest way.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.