this
A Standard script or Post Pagination script that has its scope set to "Each matched element" (see Setting the scope of a script) will be called in a loop over the elements that match the selector of the script - the results
(see results). In such a script, this
is an object of the type QueryResult. It represents the current element in the loop.
Example
If the selector of a script is p.onlyCanada
, and its scope is set to "Each matched element", the script will be repeated for all paragraphs that have the onlyCanada
class; it can access only one paragraph at a time. The script could use this
to manipulate each paragraph, e.g. hide or show it depending on the value of a data field Country
in the current record:
if (record.fields["Country"] == "CANADA") {
this.show();
} else {
this.hide();
}
results
object is still accessible, and can be used in a non-iterative way (for example, you could use its length
property to determine the total number of matched elements) but iterating over results
will produce a warning.Properties
Field | Type | Description |
---|---|---|
id | Number | Index in the result set, or zero if this element is not part of a result set. |
record |
Record |
Represents the current detail record in a (possibly nested) detail table associated with repeating rows in a Dynamic Table. This property is only available when |
runningTotal | Number | Can be used to update a running total. It is initialized to zero when a loop over results starts. |
Functions
The functions below can be called by the results
object and by any other result set that is returned by a query, see query().
Function | Description |
---|---|
add() |
Adds elements to the current HTML element. |
addClass() |
Adds the specified class to the current HTML element. Has no effect if the class is already present. |
after() | Inserts content after the current HTML element. |
append() |
Inserts content at the end of the current HTML element. |
Changes the given attribute of the current HTML element with the given value. |
|
before() | Inserts content before the current HTML element. |
children() | Returns the immediate children of the current HTML element. |
clone() | Returns a copy of the current HTML element. |
This function gets the first parent element that matches a selector, by testing the element itself and traversing up through its ancestors in the DOM tree. |
|
css() | Gets the value of a style property for the HTML element or sets one or more CSS properties for the HTML element. |
Removes the contents (child elements and inner HTML) from the current element. |
|
Performs a search for a text in the children of the current HTML element and returns a new result set with elements that surround the occurrences. |
|
hasClass() | Returns true if the current HTML element has the
specified class. |
height() | Gets or sets the outer height of an element, including padding and borders. |
Hides the HTML element. |
|
Replaces the inner HTML of the element with the supplied value, or returns the HTML of the current element if no value is supplied. |
|
info() | Post Pagination Scripts only. Returns pagination information for the current HTML element. |
is(selector) | Returns true if the current HTML element matches the supplied CSS selector. |
Returns the next sibling of the current HTML element. |
|
Returns a boolean value indicating whether the current HTML element overflows its box boundaries. |
|
pageref() |
Returns a marker that will be replaced with the element's page number after pagination. This only works for elements in the section that is currently being merged. |
parent() | Returns the parent of the HTML element. |
prepend() | Inserts content at the beginning of an HTML element or of each element in a set of HTML elements. |
Returns the previous sibling of the current HTML element. |
|
remove() | Removes an HTML element or a set of HTML elements from the document. |
removeAttr() | Removes the specified attribute from the current HTML element. |
removeClass() | Removes the specified class from the current HTML element. Has no effect if the class is not present. |
Replaces the current HTML element (with a snippet, for example). Returns the current element. |
|
show() | Shows the HTML element in the template. |
tagName() | Returns the HTML tag name of the element, in uppercase. For an example see: Creating a Table Of Contents. |
text() | Replaces the text content of the HTML element with the supplied value, or returns the text content of the element if no value is supplied. |
width() | Gets or sets the outer width of the HTML element, including padding and borders. |