handle cases when innerHTML fails
use compareDocumentPosition as a fallback for contains