2020.2

Table Of Contents
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
page1420).
l One element that matches the selector of a script that runs for "Each matched element"
(see "this" on page1338 and "Setting the scope of a script" on page860).
l The first element in a set of elements returned by a query in the template (see "query()" on
page1293).
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");
attr(attributeName, value)
Sets the value of the specified attribute of one HTML element or of each element in a result set.
attributeName
String; the name of the attribute.
value
String; value for the attribute.
Page 1309