When I click on the button "remove" of the new elements added does not happen any action. But when I click on that has already been loaded in the html it is removed. Could someone explain and help me?
<div id="ubber">
<div class="box">
<p>Box </p>
<button class="btn btn-danger remove-button">Remove</button>
</div> <!-- box -->
</div> <!-- ubber -->
<button class="btn btn-success" id="addnew">add new box</button>
<script src="jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//add
$('#addnew').on('click', function(){
$('#ubber').append('<div class="box"><p>Box <span id="sum">0</span></p><button class="btn btn-danger remove-button">Remove</button></div> <!-- box -->');
});
//remove
$('.remove-button').on('click' ,function(){
$(this).closest('div').remove();
})
});
</script>
`, removing it will be irrelevant. He wants to remove parent `.box` which `.closest('div')` would achieve. Anyways, if OP thinks the duplicate is wrong, he can always comment and we can reopen.
– Shaunak D May 16 '15 at 05:24