2019.2

Table Of Contents
while ( ! query("#mybox").overflows()) {
//do something
}
The following script selects three boxes that all have the class box (selector: .box). It loops over
them, inserting as many products from an array as possible into the box. In fact, it inserts one
too many and removes the last one before moving on to the next box.
var products =
["Appetizer","Beans","Beef","Lettuce","Sprouts","Coconut","Juice","
Soup","Coriander","Cheese","Pasta","Sugar","Vinegar","Bread"];
var i = 0;
results.each( function() {
// Add elements to the box until it overflows.
while ( ! this.overflows() && i < products.length ) {
this.append("<p>" + products[i] + "</p>");
i++;
}
// Go one step back unless we processed all items in our array.
if( i < products.length ) {
query("p:last-child", this).remove();
i--;
}
});
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.
Example
Creating a table of contents
The following script creates a table of contents for all level 1 headings (<h1> elements) with the
class title in one section.
var toc = '<ul ID="toc">';
query('h1.title').each(function()
{toc += '<li>' + this.text() + ' <span class="li_toc">' +
this.pageref() + '</span></li>';
});
Page 1317