2022.2

Table Of Contents
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");
attr()
attr(attributeName) : String
ReturnsthevalueofthespecifiedattributeofanHTMLelementwhichcanbe:
l
Thefirstelementinasetofelementsthatmatchtheselectorofascript(see"results"on
page844).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage781and"Settingthescopeofascript"onpage373).
l
Thefirstelementinasetofelementsreturnedbyaqueryinthetemplate(see"query()"on
page742).
attributeName
String;thenameoftheattribute.
Page 755