<script type="text/javascript"> var i = 0; var j = 1; $("#add").click(function(){ ++i; var c = i + j; $("#dynamicpre").append('<div class="dynamicfields mb-5"><h5>Track:' + c + '</h5></div>'); }); $(document).on('click', '.remove-tr', function(){ $(this).closest('.dynamicfields').remove(); }); </script> In the above question I am simply append a value through c variable. Now, What happen here when I click on add button it show Track:2 but when I click on remove and click again on add button then it show Track:3 but I want to show Track:2. So, How can I do this? Please help.
Thank You
https://stackoverflow.com/questions/65913164/dynamic-add-button-show-wrong-value-jquery January 27, 2021 at 01:07PM
没有评论:
发表评论