Bondsmith
Bondsmith

Reputation: 1578

How can I call a div to place under another div at the same html?

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

Answers (5)

Agus Putra Dana
Agus Putra Dana

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

Amit Kumar
Amit Kumar

Reputation: 5962

your jquery

$('.container').append($('.apple').html());

DEMO

Upvotes: 0

user3740416
user3740416

Reputation: 5

use javascript function onclick and document.getElementByID('idname ').classname="apple";

Upvotes: 0

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 15148

This should do it:

$(".apple").detach().appendTo(".container");

Upvotes: 0

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Use this : on page load, apple div get added to container div using .appendTo().

$(function(){
    $('.apple').appendTo('.container');
   });

Upvotes: 1

Related Questions