SO - 29488598
by Arun P Johny
HTML
<div class="parent">
<div class="child">
</div>
<br>
<a href="#" class="inc-child">Add one more child</a>
</div><br>
<a href="#" class="inc-parent">Add one more Parent</a>
CSS
a{
float: left;
padding: 5px 10px;
text-decoration: none;
margin-top: 10px;
color: #333;
border-radius: 5px;
background: #ccc;
}
a:hover{
color: #fff;
background: #333;
}
.child{
width: 100%;
height: 150px;
float: left;
background: orange;
}
.parent{
width: 500px;
height: auto;
padding: 20px;
float: left;
background: black;
}
JavaScript
jQuery(function($){
var _parent = $('.parent').eq(0).clone();
$(document).on('click', '.inc-child', function(){
var $p = $(this).parent();
$p.find('.child').first().clone().insertBefore(this)
})
$('.inc-parent').on('click', function(){
_parent.clone().insertBefore(this)
})
})