javascript - Jquery a .click then .slideDown div -


i have anchor when click slidedown form within div, , click again slide up. used .toggle, have multiple anchors , multiple divs same class, had rework code or else anytime clicked on of anchors divs slidedown , see 4 forms.

so, thought rewrite code .closest, doesn't seem working. think it's because .closest has go dom hierarchy, won't work div way it's laid out. tried .sibling doesn't work either. ideas?

  <a href="#" class="payment-form-show">pre-pay credit card</a>   <div style="display: none;" class="payment-form-wrapper">       <h3><?php _e('submit payment', 'jc_stripe'); ?></h3>       <form action="" method="post" id="stripe-payment-form" class="payment-form">         ...       </form>   </div>    <script>         $("a.payment-form-show").click(function() {             var e = $(this).closest("div.payment-form-wrapper");                     if (e.is(":hidden")) {                         e.slidedown("slow");                         $(this).html("don't pre-pay credit card")                     } else {                         e.slideup("slow");                         $(this).html("pre-pay credit card")                     }             return false;         });     </script> 

i think should wrap a.payment-form-show , div.payment-form-wrapper inside div. this:

<div> <a href="#" class="payment-form-show">pre-pay credit card</a>   <div style="display: none;" class="payment-form-wrapper">       <h3><?php _e('submit payment', 'jc_stripe'); ?></h3>       <form action="" method="post" id="stripe-payment-form" class="payment-form">         ...       </form>   </div> </div> 
  • when tag clicked, immediate parent , find form:

    $(this).parent().find("div.payment-form-wrapper");

  • in case, div wrapper serves context tags. create more maintainable code. because when use .next() or function .div.payment-form-wrapper, javascript code coupled current position of tags. in future, if modify position, or add tags in between, code fail.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -