Public
Edited
May 14, 2023
Insert cell
Insert cell
div = html`<div id="myDiv">This is some text.</div>`
Insert cell
{
const range = document.createRange();
range.selectNodeContents(div);
const startOffset = 5; // the character offset you want to get the position for
range.setStart(div.firstChild, startOffset);
range.setEnd(div.firstChild, startOffset + 1);
const rect = range.getBoundingClientRect();
return [rect.left, rect.top]
}
Insert cell
{
const element = html`<div>This is <span>some</span> text.</div>`
const range = document.createRange()
range.selectNodeContents(element)

console.log(div.firstChild)
const startOffset = 8
range.setStart(div.firstChild, startOffset)
range.setEnd(div.firstChild, startOffset + 1)

console.log(range)
const rect = range.getBoundingClientRect();
return [rect.left, rect.top]
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more