clone()

This function returns a copy of one HTML element or of a set of HTML elements, which can be:

  • The elements that match the selector of a script (see results).
  • One element that matches the selector of a script that runs for "Each matched element" (see this and Setting the scope of a script).
  • The elements returned by a query in the template (see query()).

To duplicate an existing template element, clone it before calling append(); see append().

This function can also be used to output a variable number of sections in each document, based on data. See: Dynamically adding sections (cloning).

Example

This script performs an iteration over the elements in the results (the elements that match the selector of the script).

Copy
var row = query("tbody tr", results).clone();
query("tbody", results).append(row);