2022.1

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>
This script looks for an element with the ID box, appends a paragraph to it and colors all 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 way the functions append() and css() are used in this script is called 'chaining'.
Chaining is optional; the same could be achieved by storing the result of the query in a
variable:
var box = query("#box");
box.append("<p>Peter Parker</p>");
box.css("color","red");
attr()
attr(attributeName) : String
Returns the value of the specified attribute of an HTML element which can be:
l The first element in a set of elements that match the selector of a script (see "results" on
page1509).
l One element that matches the selector of a script that runs for "Each matched element"
(see "this" on page1425 and "Setting the scope of a script" on page924).
l The first element in a set of elements returned by a query in the template (see "query()" on
page1379).
Page 1437