JSFiddle - React, Tailwind, and code Playground
by bisque
HTML
<p>選択範囲を取得する</p>
<div id="result"></div>
JavaScript
document.addEventListener("mouseup", () => {
const selection = window.getSelection();
const anchorOffset = selection.anchorOffset;
const focusOffset = selection.focusOffset;
renderResult({anchorOffset, focusOffset})
});
function renderResult(obj) {
document.getElementById("result").textContent = JSON.stringify(obj);
}