var range = document.createRange(); range.selectNodeContents(document.getElementById('foo')); window.getSelection().addRange(range); console.log(window.getSelection().toString()); console.log(window.getSelection().getRangeAt(0).toString()); <div id="foo">Ва<p>ся</div> In the first case, “Vasya” was derived separately, in the second - “Vasya” together. And Chrome prints "Wah sy" in two lines, and Firefox - in three lines, adding another empty one.
Is such differentiated behavior standardized? Can it be managed? Bug or feature? Is there any specific list of tags that could lead to such a separation? (For comparison, Ва<em>ся</em> does not divide anything in both cases.) Running through the eyes of the Selection API did not give anything sensible.