2022.2

Table Of Contents
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.
if (record.fields["Country"] == "CANADA") {
results.show();
} else {
results.hide();
}
tagName()
ReturnstheHTMLtagnameofoneHTMLelementinuppercase(e.g.H1,P,ARTICLE).
Example
ThisPostPaginationScriptfindslevel1and2headingsinallPrintsectionsandstorestheirpagenum-
ber,textandHTMLtagname.
merge.context.query("h1, h2").each(function() {
var pageNo = this.info().pageNo;
var text = this.text();
var level = this.tagName();
});
Page 1268