Skip to content

Instantly share code, notes, and snippets.

View canhuyh's full-sized avatar
🤪
crazy

CANHUYH canhuyh

🤪
crazy
  • Vietnam
View GitHub Profile
@canhuyh
canhuyh / contenteditable-caret-position.js
Created January 27, 2024 14:13 — forked from loilo/contenteditable-caret-position.js
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()