Consider this scenario: an existing div with the class
<div class="two">TWO</div>
. When this div is clicked, a new div called .one
should be added, wrapping the .two
like so: <div class="one"><div class="two">TWO</div></div>
. Do you have any suggestions on how to achieve this? I have tried using wrap and prepend methods without success.
$(".two").click(function(){
$(".one").wrap(this);
});
.one{
padding:10px;
background-color:#ff0;
}
<div class="two">TWO</div>