jquery - how to add effect 'hide ("slow")' to div inside a PHP while -


i have form repeated several times within div called "formscontainer" in php while, want make form submit respective div disappears effect hide ("slow")

here example code

<script type="text/javascript">  $(function() {       $("form").each(function() {           $(this).validate( {               submithandler: function(formbeingsubmitted) {                   $.post('process.php', $(formbeingsubmitted).serialize(), function(data) {                       $('#results').html(data);                       $ (formbeingsubmitted).hide("slow");                   });               }           });       });   }); </script> </head> <body> <?php { ?> <div id="formscontainer">   <form method="post" id="form1">     <label for="name" id="name_label">form </label>       <input type="text" name="name" id="name" size="30" value=""/>       <br>      <input type="submit" name="submit" value="send">    </form> </div> <div id="formscontainer">   <form method="post" id="form1">     <label for="name" id="name_label">form </label>       <input type="text" name="name" id="name" size="30" value=""/>       <br>      <input type="submit" name="submit" value="send">    </form> </div> <div id="formscontainer">   <form method="post" id="form1">     <label for="name" id="name_label">form </label>       <input type="text" name="name" id="name" size="30" value=""/>       <br>      <input type="submit" name="submit" value="send">    </form> </div> <?php } while ($row_var = mysql_fetch_assoc($var)); ?> <div id="results"></div> </body> </html> 

$(function () {     $("form").each(function () {         var par_div = $(this).closest('div'); //finding closest div         $(this).validate({             submithandler: function (formbeingsubmitted) {                 $.post('process.php', $(formbeingsubmitted).serialize(), function (data) {                     $('#results').html(data);                     $(formbeingsubmitted).hide("slow");                     par_div.hide('slow'); //hide div                 });             }         });     }); }); 

you can use

$(this).parents('div'); instead of $(this).closest('div');

but $(this).closest('div'); faster


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -