function clicked() {
const container = document.getElementById("container");
const selection = window.getSelection();
for (let i = 0; i < selection.rangeCount; i++) {
const range = selection.getRangeAt(i);
range.setStart(range.startContainer, 0);
range.setEnd(range.startContainer, range.startContainer.length);
}
}< /code>
With "contenteditable" not enabled
span1
span2
With "contenteditable" enabled
span3
span4
Tests
Whilst holding down CTRL, use your cursor to partially select text of:
- span1 and span2, then press the button.
(The selections expand correctly.) - span3 and span4, then press the button.
(The selections do not expand correctly.) - span3, then press the button.
(The selection expands correctly.) - span1, span2, span3, and span4, then press the button.
(The selections expand correctly, once again.)
< /div>
< /div>
< /p>
Я хочу, чтобы второй тест вел, как и другие. Недостаток).
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-contente