2022.2

Table Of Contents
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
page1301).
l
Oneelementthatmatchestheselectorofascriptthatrunsfor"Eachmatchedelement"(see
"this"onpage1237and"Settingthescopeofascript"onpage813).
l
Thefirstelementinasetofelementsreturnedbyaqueryinthetemplate(see"query()"on
page1197).
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");
attr(attributeName, value)
SetsthevalueofthespecifiedattributeofoneHTMLelementorofeachelementinaresultset.
attributeName
String;thenameoftheattribute.
value
String;valuefortheattribute.
Examples
ThisscriptlooksupanimageinanelementwiththeID#calloutboxandsetsitsalternativetexttoa
valuefromadatafield.
var altText = record.fields.FavHobby;
query("#callout img").attr('alt', altText);
Page 1247