2022.2

Table Of Contents
Example
ThisPostPaginationScriptfindslevel1and2headingsinallPrintsectionsandstorestheirpagenum-
ber,textandHTMLtagname.
merge.context.query("h1, h2").each(function() {
var pageNo = this.info().pageNo;
var text = this.text();
var level = this.tagName();
});
Thiscodeisusedinascriptthatinsertsatableofcontents.Forthefullscriptandexplanationsee
"CreatingaTableOfContents"onpage411.
text()
text() : String
ReturnsthetextcontentofanHTMLelementorofthefirstelementinaresultset(see"results"on
page844).
Example
Thisscriptloadsasnippetintoavariableandretrievesanelementfromthesnippetusingquery()
andtext().
var mysnippet = loadhtml('snippets/text-root-wrapped.html');
var subject = query("#subject", mysnippet).text();
results.append("<p style='font-weight: bold;'>" + subject + "</p>");
text(value)
ReplacesthetextcontentofoneHTMLelementorofeachelementinaresultsetwiththesupplied
value.
Example
Thisscriptloadsasnippet,thenlooksforplaceholdersusingfind(),andreplacesthemusingtext
(value).
var mysnippet = loadhtml('snippets/snippet.html');
mysnippet.find('@var1@').text('OL Connect 1');
mysnippet.find('@var2@').html('<i>OL Connect 2</i>').css('text-decoration','underline');
results.replaceWith(mysnippet);
width()
Getsorsetstheouterwidth,includingpaddingandborders,ofanHTMLelementorofthefirstelement
inresultset(see"results"onpage844),i.e.thesetofHTMLelementsthatmatchtheselectorofthe
Page 812