2018.1

Table Of Contents
line item to the list, with the text (this.text()) and the page reference of the respective
heading.
After the loop, the end tag of the list is added to the variable.
Finally, the script adds the variable - that now contains the table of contents - after the results.
The results object contains the elements that match the selector of the script. So, if the script's
selector selects the title of the table of contents, the table of contents will be added after that.
The following style rules, added to the style sheet, will align the chapter titles to the left and the
page numbers to the right:
#toc li {
text-align:left;
}
#toc span {
float: right;
}
Note that these styles use the list's ID, that was defined in the first line of code. For information
about style sheets, see "Styling templates with CSS files" on page239.
parent()
Returns the parents of the elements in a set. (In HTML, a parent is an element that contains
another element.)
To get an ancestor that matches a particular selector, use closest() (see "Examples" on
page649).
Example
Assume that there are three paragraphs in a Box and that one of those paragraphs matches the
selector of this script. The paragraph is stored in the results object (see "results" on page633).
The script retrieves the Box (which is the parent of the paragraph) using results.parent(), and
then changes its background color to red.
results.parent().css('background-color' , 'red');
prepend()
Insert contentat the beginningof each element in the set of HTML elements that match the
selector of the script or of another query in the template (see "query()" on page680).See also:
"Examples" on page641.
Page 656