Bugfix for orpheaned node

I sometime get an error inside JS console, the `api.dom.hasParents` function fails because of some node outside the document. This seems the fix the bug.