Hello, please help understand the principle of compareDocumentPosition ().
Experimented in the console:
var div=document.createElement('div'); div.innerHTML="<span><span><span><span><span>span</span></span></span></span></span> div.appendChild(document.createElement('p')) It turned out this:
<div> <span> <span> <span> <span> <span>"s"</span> </span> </span> </span> </span> <p></p> </div> Now apply nodeA.compareDocumentPosition(nodeB)
r = div.childNodes[0].compareDocumentPosition(div.childNodes[1])//r=4 r.toString(2)="100" Everything is clear here, nodeA precedes nodeB
But the next result is not clear to me.
r1 = div.childNodes[0].compareDocumentPosition(div) //r1=10 r1.toString(2)="1010" r2 = div.childNodes[0].childNodes[0].compareDocumentPosition(div) //r2=10 r2.toString(2)="1010" Actually a question. Why is the result 10 and not 8 (nodeB contains nodeA), and what does 10 mean? Also, should the results of r1 and r2 not be different? (the nesting level is different)