2022.2

Table Of Contents
Matched element Matched element after script execution
<divid="box">
<p>PeterParker</p>
</div>
<divid="box">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
Thisscriptusesthefunctionquery()tofindabox,prependsaheadingandsetsthetextcolorofthe
entireboxtored.
query("#box").prepend("<h1>Personal information</h1>").css("color","red");
Matched element Matched element after script execution
<divid="box">
<p>PeterParker</p>
</div>
<divid="box"style="color:red;">
<h1>Personalinformation</h1>
<p>PeterParker</p>
</div>
Note: Thewaythefunctionsprepend()andcss()areusedinthisscriptiscalled'chaining'.Chain-
ingisoptional;thesamecouldbeachievedbystoringtheresultofthequeryinavariable:
var box = query("#box");
box.prepend("<p>Peter Parker</p>");
box.css("color","red");
prev()
prev()returnstheprevioussiblingofanHTMLelement,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).
InHTML,siblingsareHTMLelementsthatsharethesameparent,i.e.HTMLelementsinthesamecon-
tainerelement.
Notethatasiblingcanbeadifferenttypeofelement.Forexample,ifaparagraph,animageandatable
followeachotherinthesameBox,theyaresiblings.
Tip: Togetthenextsibling,usenext()(see"next()"onpage1258).
Page 1264