Forum How do I...?

Index from hidden terms

My book has index terms in spans like this:
<span class='indexterm' ><span class='primary'>Collections</span><span class='secondary'>interfaces for</span></span> 
<span class='indexterm'><span class='primary'><code>Vector</code></span>

In the book, I hide them with
.indexterm {
    display: none;

I don't expect a fully automated solution from Prince. Just logging them with page numbers is good enough. I had a look at several JavaScript examples, but I am unsure how I would get those page numbers. Or rather, the page numbers of their parents since they are not being displayed.Thanks for any hints!
Hi, there is a sample about creating index for books on and the javascript used in that example is available at
I am trying the simplest thing, but I cannot get page numbers. getPrinceBoxes always returns an array of length 0.

Prince.registerPostLayoutFunc(() => {
  var is = document.querySelectorAll(".indexterm")
  for (var i = 0; i < is.length - 1; i++) {
    var boxes = is[i].parentNode.getPrinceBoxes()
    for (var j = 0; j < boxes.length; j++) 

I see lots of matches for the selector. Since it is not displayed, I look at the boxes of the parent. But no dice, erm, boxes. All the boxes.length return 0.

Edited by cayhorstmann

Never mind--I just realized I need to set

Prince.trackBoxes = true;