Replace `Element.contains` with `Element.compareDocumentPosition`

`Element.contains` doesn't work for text nodes.