Skip to content

Instantly share code, notes, and snippets.

View AbdulhadiJarad's full-sized avatar

AbdulhadiJarad

View GitHub Profile
@loilo
loilo / contenteditable-caret-position.js
Last active October 30, 2024 14:16
Some utilities for detecting the caret position inside a contenteditable element
/**
* Get the number of characters in an element
*
* @param {Element} element
* @return {number}
*/
function getTextLength(element) {
let range = element.ownerDocument.createRange()
range.selectNodeContents(element)