• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Clone an element

Clone an element

Clone an element

Using the cloneNode(true) method will deep copy a given element. In the sample code below, all attributes and children of the original node ele will be cloned in cloned as well.

const cloned = ele.cloneNode(true);

Passing false produces a cloned node that keeps only the attributes and the original node:

const cloned = ele.cloneNode(false);

Source

https://htmldom.dev/clone-an-element/

Miscellaneous

Related Snippets:

  • Drop list elements from the left
  • How To Loop Through All The Entries In An Array Using JavaScript
  • Determine whether two values are the same value
  • Get size of the selected file

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers