Reputation: 898
I have a div named childDiv
which lives inside parentDiv
.
<div id="parentDiv">
<p>Parent should be on top</p>
<div id="childDiv">
<p>Child</p>
</div>
</div>
When the user clicks a button, I want childDiv
to be appended to the modal dialog window. However, once the the user closes the modal, I want childDiv
to go back to the parentDiv
.
$(document).ready(function () {
$("#myBtn").click(function () {
$("#myModal").modal('show');
$("#childDiv") .appendTo(".modal-body");
});
$('#myModal').on('hide.bs.modal', function (e) {
$("#childDiv") .prependTo("parentDiv");
})
});
Please see the below fiddle. I would appreciate your help!
Upvotes: 1
Views: 983
Reputation: 144689
The selector is wrong, you are missing #
for the ID selector:
$("#childDiv").prependTo("#parentDiv");
Upvotes: 1