How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Duplicate a DIV into Another DIV with jQuery
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • Tools
  • Prank Screens
  • Learn
  • Blog
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Duplicate a DIV into Another DIV with jQuery
Web Development

How to Duplicate a DIV into Another DIV with jQuery

how7o
By how7o
Last updated: May 22, 2026
4 Min Read
Duplicate a div into another div with jQuery clone
SHARE

To duplicate a div into another div with jQuery, use .clone() to get a copy of the element and an insertion method like .appendTo() or .html() to place it into the target. For the common case of a popup or preview that mirrors some source content, .clone() is the cleaner choice.

Contents
  • Starting markup
  • Option 1 — .clone() (recommended)
  • Option 2 — .html() (string copy)
  • Cloning with event handlers
  • Strip or rewrite ids on the clone
  • Vanilla JS equivalent
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with jQuery 3.7. Originally published 2022-10-26, rewritten and updated 2026-05-17.

Starting markup

<div class="content">
    <h1>Title</h1>
    <p>Some Content</p>
</div>

<div class="popup">
    <!-- duplicate goes here -->
</div>

Option 1 — .clone() (recommended)

var elem = $('.content').clone();
$('.popup').html(elem);

.clone() returns a duplicate jQuery object that’s detached from the DOM. .html(elem) replaces the inner content of .popup with it, including the outer <div class="content"> wrapper.

jQuery duplicate div — clone vs html, with/without events, deep id handling

Option 2 — .html() (string copy)

var elem = $('.content').html();
$('.popup').html(elem);

This copies only the inner markup of .content (the <h1> and <p>, not the wrapping div). Same .html() method is doing two different things here: with no argument it’s a getter that returns a string; with an argument it’s a setter that replaces inner HTML.

Cloning with event handlers

// Shallow clone — copies markup, drops event handlers
$('.content').clone();

// Deep clone — copies jQuery data + events on the cloned element
$('.content').clone(true);

// Deeper still — events on the element AND all its descendants
$('.content').clone(true, true);

Default is structure-only. Pass true when you want a true behavioural copy.

Strip or rewrite ids on the clone

var cloned = $('.content').clone();

// Strip every id from the clone and its descendants
cloned.find('[id]').addBack('[id]').removeAttr('id');

$('.popup').html(cloned);

HTML id attributes must be unique per page. Cloning a subtree that contains ids and inserting it elsewhere will silently duplicate them — labels stop pointing at the right input, CSS rules match more than one element. Strip them or rewrite them with a fresh prefix on the clone.

Vanilla JS equivalent

const source = document.querySelector('.content');
const target = document.querySelector('.popup');

// Element clone
target.innerHTML = '';
target.appendChild(source.cloneNode(true));

// Or: string copy (equivalent of .html())
target.innerHTML = source.innerHTML;

Frequently asked questions

Should I use .clone() or .html() to copy a div?

.clone() returns an element (with all of its descendants, attributes, and optionally its event handlers); .html() returns the inner HTML as a string. If you want a full structural copy with the outer wrapper, use .clone(). If you only need the inner markup re-injected, .html() is fine and slightly cheaper.

Does .clone() copy event handlers too?

Only when you pass true: $('.content').clone(true) includes attached jQuery data and event handlers; $('.content').clone(true, true) also copies handlers on every descendant. Without the argument, only DOM structure and attributes are copied — useful when you want a clean copy that won’t fire stale handlers.

How do I avoid duplicate id attributes when cloning?

id values must be unique per page. After cloning, walk the new tree and either strip ids (cloned.find('[id]').addBack('[id]').removeAttr('id')) or rewrite them to a fresh prefix. Forgetting this is a common cause of subtle bugs — labels stop linking to the right input, CSS rules match more than one element, etc.

Is there a vanilla JS equivalent?

Yes: node.cloneNode(true) clones the element with all descendants, and target.append(clone) inserts it. target.innerHTML = source.innerHTML is the string-copy equivalent of .html(). Both work without jQuery on every modern browser.

Related guides

  • How to Check if an Element Is Visible or Hidden with jQuery
  • How to Check if a Checkbox Is Checked with jQuery
  • How to Disable or Enable an Input with JavaScript or jQuery

References

jQuery .clone(): api.jquery.com/clone. jQuery .html(): api.jquery.com/html. Node.cloneNode(): developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode.

TAGGED:domJavaScriptjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Disable and enable a form input with JavaScript and jQuery How to Disable or Enable an Input with JavaScript or jQuery
Next Article Enable the PHP DOM extension on a Linux server How to Enable the PHP DOM Extension
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

You Might Also Like

Laravel get config variable — config() helper and Config facade resolving dotted keys
Web Development

How to Get Config Variables in Laravel

7 Min Read
PHP delete array element — unset, array_splice, array_filter, array_search
Web Development

How to Delete an Element from a PHP Array

7 Min Read
Scroll to an element on a web page with jQuery
Web Development

How to Scroll to an Element Using jQuery

4 Min Read
Break out of a jQuery .each() loop with return false
Web Development

How to Break Out of a jQuery .each() Loop

5 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Nintendo Switch Update Screen
  • Fake PlayStation Update Screen
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?