• 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:

  • Tell the browser when to run your JavaScript code
  • Remove HTML/XML tags from a string
  • How To Format Numbers as Currency Strings in JavaScript
  • Find a specific object in an array of objects

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