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 January 27, 2024 14:13
JavaScript Contenteditable Caret Position Utilities
// 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()