Reputation: 1578
I need to call a div by its class, to be placed under another div. Both divs are at the same html (but I want to have them separated for some reasons).
For example I have something like this:
<div class="apple">
</div>
.
.
.
<div class="container">
I need to call "apple" to be here.
</div>
I know I can just put "apple" inside "container" since they both are at the same html, but in my case I want them to be separated.
Upvotes: 0
Views: 2056
Reputation: 719
You can use appendTo() or append() method. You can see the code here http://codepen.io/agus-pd/pen/JqBGD
$(".apple").appendTo(".container");
in this example I use appendTo method.
Upvotes: 0
Reputation: 5
use javascript function onclick and document.getElementByID('idname ').classname="apple";
Upvotes: 0
Reputation: 15148
This should do it:
$(".apple").detach().appendTo(".container");
Upvotes: 0
Reputation: 28513
Use this : on page load, apple
div get added to container
div using .appendTo().
$(function(){
$('.apple').appendTo('.container');
});
Upvotes: 1