29 of 119 menu

The clone method

The clone method creates deep copies of the selected page elements and returns them as a jQuery object. The elements are copied along with all the elements inside them. The optional parameters control whether to copy event handlers attached to these elements (default false - do not copy).

Syntax

The method can be passed two optional parameters, which can take the values ​​true or false (false by default). For the first parameter with the value true - event handlers and data for the element will also be copied, with false - they will not. For the second parameter with the value true - event handlers and data for all descendants of the cloned element will also be copied, with false - they will not.

.clone([flag1], [flag2]);

Example

Let's insert another one of the same after the paragraph using the clone method and the insertAfter method:

<p class="www">text</p> $('.www').clone().insertAfter('.www');

See also

  • method after,
    which adds content after the given element
  • method before,
    which adds content before the given element
  • method remove,
    which deletes elements without the possibility of their recovery
  • method detach,
    which removes elements with the possibility of their recovery
enru