2022.2

Table Of Contents
Note: Thewaythefunctionsadd()andcss()areusedinthisscriptiscalled'chaining'.Chaining
isoptional;thesamecouldbeachievedbystoringtheresultsofthequeriesinavariable:
var myResult = query("#test1");
myResult.add(query("#test2");
myResult.css("background", "yellow");
Thefollowingscriptloadssnippetsinaniterationandaddstheirelementstoanemptyresultset(using
query()).Thenitreplacesaplaceholderinthetemplatewiththenewresult.
var chapters = query();
for ( var i = 1; i <= 4; i++) {
chapters = chapters.add(loadhtml('snippets/Chapter' + i + '.html'));
}
results.replaceWith(chapters);
Selector Matched element Matched element after script execution
#chapters <pid="chapters">{{chapters}}</p> <h1>Chapter1</h1>
<p>Loremipsum...</p>
<h1>Chapter2</h1>
<p>Loremipsum...</p>
<h1>Chapter3</h1>
<p>Loremipsum...</p>
<h1>Chapter4</h1>
<p>Loremipsum...</p>
addClass()
Addsthespecifiedclass(es)tooneoremoreHTMLelements,whichcanbe:
l
Theelementsthatmatchtheselectorofascript(see"results"onpage844).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage781and"Settingthescopeofascript"onpage373).
l
Theelementsreturnedbyaqueryinthetemplate(see"query()"onpage742).
Addingaclasshasnoeffectiftheclassisalreadypresent.
addClass(classname)
Addsthespecifiedclass(es)tooneormoreHTMLelements.Thishasnoeffectiftheclassisalready
present.
classname
Page 784