$id(id, context) requires context to be a document node.
Simplify DOM.contains()
And contains() returns false rather than null if other tests fail.