I have this code I am working on create.blade.php
I have followed this question and this tutorial in order to replicate a div
. I have managed to clone the div
and display. My issue comes when I try removing the added div
as it does not work. How do I go about it? I have added the remove function to my script.
$(document).ready(function() {
$(".add").click(function() {
$("#education-clone").clone().appendTo("#edu");
});
$(".remove").click(function() {
$("#education-clone").remove(this);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="profile-card" id="education">
<h5>Education</h5>
<div id="edu">
<div class="form-row" id="increment">
<div class="form-group col-md-6">
<label>School</label>
<input type="text" class="form-control" name="school[]" placeholder="School/University">
</div>
<div class="form-group col-md-2">
<label>From</label>
<input type="date" class="form-control" name="school_from[]" placeholder="From">
</div>
<div class="form-group col-md-2">
<label>To</label>
<input type="date" class="form-control" name="school_to[]" placeholder="To">
</div>
<div class="form-group col-md-2">
<label>Action</label>
<button class="form-control btn add" type="button">Add</button>
</div>
</div>
<div class="form-row" id="education-clone">
<div class="form-group col-md-6">
<label>School</label>
<input type="text" class="form-control" name="school[]" placeholder="School/University">
</div>
<div class="form-group col-md-2">
<label>From</label>
<input type="date" class="form-control" name="school_from[]" placeholder="From">
</div>
<div class="form-group col-md-2">
<label>To</label>
<input type="date" class="form-control" name="school_to[]" placeholder="To">
</div>
<div class="form-group col-md-2">
<label>Action</label>
<button class="form-control btn-danger remove" type="button">Remove</button>
</div>
</div>
</div>
<br>
<button class="btn">Next</button>
</div><br>