2022.2

Table Of Contents
replaceWith(content)
ReplacesoneHTMLelementoreachelementinasetofHTMLelements.Returnstheresultset.
content
Aqueryresult.ThiscanbeanHTMLstringoraresultset.
Examples
Replace elements with a snippet
Thefollowingscriptloadsasnippetandthenreplacestheelementsmatchedbythescript'sselector
withthesnippet.
var snippet = loadhtml('snippets/mysnippet.html');
results.replaceWith(snippet);
Replace elements with a set of snippets
Thefollowingscriptloadssnippetsandaddstheirelementstoanew,emptyresultset(usingquery
()).Thenitreplacesaplaceholderinthetemplatewiththesetofsnippets.
var chapters = query();
for ( var i = 1; i <= 4; i++) {
chapters = chapters.add(loadhtml('snippets/Chapter' + i + '.html'));
}
results.replaceWith(chapters);
show()
ShowsoneormoreHTMLelements,whichcanbe:
l
Theelementsthatmatchtheselectorofascript(see"results"onpage1301).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage1237and"Settingthescopeofascript"onpage813).
l
Theelementsreturnedbyaqueryinthetemplate(see"query()"onpage1197).
Tohideelements(again),usethefunction"hide()"onpage1256.
ThesefunctionsareusedbytheConditionalScriptWizard,asyoucanseewhenyouopenaCondi-
tionalScriptandclicktheExpandbutton;see"Showingcontentconditionally"onpage734.
Example
Thisscripthidesorshowstheelementsmatchedbytheselectorofthescript(whicharestoredinthe
resultsobject),dependingonthevalueofthedatafieldCountryinthecurrentrecord.
Page 1234