2021.2

Table Of Contents
Targeting text
Text in itself cannot have an ID or class, but the element that contains it can. The smallest
possible container of text is a Span. To learn how to put text inside a Span, see "Span" on
page699. Give the Span an ID or class and use that as the script's selector.
To target text in a bigger container (a paragraph, for example), change the Find method of the
script to Selector and Text, use the ID or class of the container element as Selector and type
the text in the Text field.
Note
When you use the drag-and-drop method (without pressing the ALT key) to insert
variable data into a template, the script's selector is by default the class of the element - a
Span or Div - in which the placeholder is wrapped. For more information see: "Inserting
variable data directly (drag-and-drop)" on page806.
Avoid DOM manipulations
The Scripting API of the Designer is a very powerful tool to manipulate and personalize your
document. But keep in mind that DOM manipulation commands like append(), prepend(),
before() and after() are resource intensive.
Try avoiding DOM modifications, especially within loops. Storing the content in a variable and
appending the information after the loop is more efficient: this way, the template will be touched
only once.
Example
The following example loads a snippet into a variable and uses the find() and text() commands
of the Designer scripting API.
var labelElm = loadhtml('snippets/label.html');
for(var i = 0; i < record.tables.products.length; i++) {
var label = labelElm.clone();
label.find('@ProductLabel@').text(record.tables.products
[i].ProductDescription);
results.after(label);
}
Page 893