I have a script that removes the duplicated form when clicked. But when you hit remove I want to only remove the form the was cloned. I believe i need to use $this
but not sure how?
jQuery
$(".remove").click(function() {
$('.duplicate').remove();
});
HTML
<div class="duplicate">
<p>Form Duplicate</p>
<a href="#" class="add">Add Guest</a> | <a href="#" class="remove">Remove </a>
</div>
<div class="duplicate">
<p>Form Duplicate</p>
<a href="#" class="add">Add Guest</a> | <a href="#" class="remove">Remove </a>
</div>
Here's a live preview: /.
Thanks!
I have a script that removes the duplicated form when clicked. But when you hit remove I want to only remove the form the was cloned. I believe i need to use $this
but not sure how?
jQuery
$(".remove").click(function() {
$('.duplicate').remove();
});
HTML
<div class="duplicate">
<p>Form Duplicate</p>
<a href="#" class="add">Add Guest</a> | <a href="#" class="remove">Remove </a>
</div>
<div class="duplicate">
<p>Form Duplicate</p>
<a href="#" class="add">Add Guest</a> | <a href="#" class="remove">Remove </a>
</div>
Here's a live preview: http://www.waterfrontexeter.co.uk/preordernew/.
Thanks!
Share Improve this question edited Mar 21, 2013 at 14:21 VisioN 145k34 gold badges287 silver badges289 bronze badges asked Mar 21, 2013 at 13:57 BrentBrent 2,48510 gold badges41 silver badges64 bronze badges 1- Here's my answer for [remove clone][1] [1]: stackoverflow./questions/6985899/… – Ravi Kant Commented Oct 15, 2013 at 6:08
1 Answer
Reset to default 6Just use closest()
and don't forget about preventDefault()
:
$(".remove").click(function(e) {
$(this).closest(".duplicate").remove();
e.preventDefault();
});