2022.2

Table Of Contents
Selector Matched element Matched element after script execution
#box <divid="box">
<h1>Personalinformation</h1>
</div>
<divid="box">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
ThisscriptlooksforanelementwiththeIDboxandappendsaparagraphtoit.
query("#box").append("<p>Peter Parker</p>");
Matched element Matched element after script execution
<divid="box">
<h1>Personalinformation</h1>
</div>
<divid="box">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
ThisscriptlooksforanelementwiththeIDbox,appendsaparagraphtoitandcolorsalltextinsidethe
boxred.
query("#box").append("<p>Peter Parker</p>").css("color","red");
Matched element Matched element after script execution
<divid="box">
<h1>Personalinformation</h1>
</div>
<divid="box"style="color:red;">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
Note: Thewaythefunctionsappend()andcss()areusedinthisscriptiscalled'chaining'.Chain-
ingisoptional;thesamecouldbeachievedbystoringtheresultofthequeryinavariable:
var box = query("#box");
box.append("<p>Peter Parker</p>");
box.css("color","red");
Page 1246