I am new to jquery and I am trying to make this code works but no way:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="add">Add</button>
<script>
$(document).ready(function(){
$("button.add").click(function() {
$(this).after('<div><button class="remove">Remove</button></div>');
});
//Remove items from cart
$("button.remove").click(function(){
$(this).fadeOut();
});
});
</script>
When I try adding the following line <div><button class="remove">Remove</button></div>
after the add button
in the initial code, everything works properly. Anytime I add new remove buttons using the JS code, it works but i can not remove those buttons.
Kindly help me fix it.