Fix querying detached nodes and document fragments by id

This PR should fix [issue #17699](https://bugs.dojotoolkit.org/ticket/17699).
Some tests fail in Internet Explorer if you remove `root.ownerDocument`.