class method Element.clone

View source on GitHub →

Element.clone(element, deep) → Element
  • deep (Boolean) – Whether to clone element's descendants as well.

Returns a duplicate of element.

A wrapper around DOM Level 2 Node#cloneNode, Element.clone cleans up any expando properties defined by Prototype.

Example
<div class="original">
  <div class="original_child"></div>
</div>
 var clone = $('original').clone();
clone.className;
// -> "original"
clone.childElements();
// -> []
 var deepClone = $('original').clone(true);
deepClone.className;
// -> "original"
deepClone.childElements();
// -> [div.original_child]

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.