2022.2

Table Of Contents
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.
Examples
Thisscript-withtheselectorimg-storesthesourceofthefirstimageinavariable.
var src = results.attr("src");
ThefollowingscriptlooksupanimagewiththeID#image1andstoresitsbackgroundcolorinavari-
able.
var imgURL = query("#image1").attr("src");
Page 790