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()).

See also: Dynamically adding sections (cloning).

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

Examples

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);

The following script clones an existing table row to match the number of rows in a detail table. Then it iterates over the rows to populate the fields.

The following script clones and populates a boilerplate row. Once completed you will need to hide the boilerplate row.