selectionStart and selectionEnd in contenteditable element

Try this, it returns the selected text, no matter if it’s contentEditable or not. function GetSelectedText() { if (document.getSelection) { // all browsers, except IE before version 9 var sel = document.getSelection(); // sel is a string in Firefox and Opera, // and a selectionRange object in Google Chrome, Safari and IE from version 9 … Read more

selectionStart/selectionEnd on input type=”number” no longer allowed in Chrome

Selection is only permitted with text/search, URL, tel and password. The likely reason that selection has been disabled for inputs of type number is that on some devices, or under some circumstances (e.g., when the input has been is presented as a short list), there might not be a caret. The only solution I have … Read more

Get contentEditable caret position

The following code assumes: There is always a single text node within the editable <div> and no other nodes The editable div does not have the CSS white-space property set to pre If you need a more general approach that will work content with nested elements, try this answer: https://stackoverflow.com/a/4812022/96100 Code: function getCaretPosition(editableDiv) { var … Read more