<!DOCTYPE HTML>
<html>
<head>
<title>
How to copy the content of a div
into another div using jQuery ?
</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
</head>
<body id = "body" style = "text-align:center;">
<h1 style = "color:green;" >
Soltuts.com
</h1>
<p id = "soltuts_up"></p>
<div class="parent">
Outer DIV
<div class="child">
Inner DIV
</div>
</div>
<br>
<div class="parent" id = "parent2">
Outer DIV
</div>
<br>
<button onclick = "soltuts_copy()">
click here
</button>
<p id = "soltuts_down"></p>
</body>
</html>
<!-- see more https://soltuts.com -->
var up = document.getElementById('soltuts_up');
var down = document.getElementById('soltuts_down');
up.innerHTML = "Click on the button to "
+ "copy a DIV into another DIV.";
function soltuts_copy() {
$('.child').clone().appendTo('#parent2');
down.innerHTML = "Inner DIV is copied"
+ " to another element.";
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.