clone() method in jQuery

clone() in jQuery

This method copies the set of matched elements with all of its descendant elements and text nodes.

Syntax

$(selector).clone([withDataAndEvents][,deepWithDataAndEvents])

  • withDataAndEvents - It denotes a Boolean indicating whether event handlers and data should be copied along with the elements. The default value is false.
  • deepWithDataAndEvents - It denotes a Boolean indicating whether event handlers and data for all children of the cloned element should be copied.

Example 1

Try Yourself

Example 2 - Just clone the element without events

Try Yourself

Example 3 - Clone the element with its events

Try Yourself

Example 4 - Clone the specified element with its events and without child element events

Try Yourself

Example 5 - Clone the specified element with its events and child element events

Try Yourself