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
Post a Comment