I'm using the .remove() function from within jQuery to try and remove a form from a DIV on a page that I've created but it doesn't see to work. Is there anything wrong with my code?
I've used an alert to see if the actual line is being fired and it definitely is. Basically I have a delete button on a page, which I'm hoping will remove the last form added but it doesn't do this. I saw the .last() function but don't know if I can use it in this context?
HTML:
<input type="button" value="Delete Row" class="removePlacement button blue" />
<div id="placement">
<form id="placement-form" class="placement-form">
<!-- items -->
</form>
<form id="placement-form1" class="placement-form">
<!-- items -->
</form>
<form id="placement-form2" class="placement-form">
<!-- items -->
</form>
<form id="placement-form3" class="placement-form">
<!-- items -->
</form>
</div>
jQuery:
$(function() {
$('.removePlacement').click(function() {
$('#placement').remove('form').last();
// alert('0');
});
});
Try:
$(function() {
$('.removePlacement').click(function() {
$('#placement').find("form:last").remove();
// alert('0');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With