index: Fix attached elements

Passing `document` into the private `selector` function throws a `TypeError`.  This will happen when an (attached) element is provided whose parents don't have IDs.

Closes #4.