look into  compareDocumentPosition