2022.1

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 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).
attributeName
String; the name of the attribute.
Examples
This script - with the selector img - stores the source of the first image in a variable.
var src = results.attr("src");
The following script looks up an image with the ID #image1 and stores its background color in a
variable.
var imgURL = query("#image1").attr("src");
Page 1396