2022.2

Table Of Contents
add(content)
Theadd()functionaddsHTMLcontenttooneormoreHTMLelementsandreturnstheunionofthisres-
ultorresultsetandothercontent.
content
Aqueryresult.ThiscanbeanHTMLstringoraresultset.
Examples
Thisscriptaddsonequeryresulttoanotherandsetsthebackgroundcolortoyellow.
query("#test1").add(query("#test2")).css("background", "yellow");
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:
Page 749