replaceWith()

Replaces each element in a set of HTML elements.

replaceWith(content)

Replaces each element in a set of HTML elements. Returns the result set.

content

A query result. This can be an HTML string or a result set.

Examples

Replace elements with a snippet

The following script loads a snippet and then replaces the elements matched by the script's selector with the snippet.

var snippet = loadhtml('snippets/mysnippet.html'); 
results.replaceWith(snippet);

Replace elements with a set of snippets

The following script loads snippets and adds their elements to a new, empty result set (using query()). Then it replaces a placeholder in the template with the set of snippets.

var chapters = query(); 
for ( var i = 1; i <= 4; i++) {
chapters = chapters.add(loadhtml('snippets/Chapter' + i + '.html'));
}
results.replaceWith(chapters);
 
  • Last Topic Update: 07:59 AM Dec-20-2016
  • Last Published: 2019-05-22 : 2:52 PM