jquery Programming Glossary: document.createrange
Text selection in div(contenteditable) when double click http://stackoverflow.com/questions/12920225/text-selection-in-divcontenteditable-when-double-click range.moveToPoint x y else if typeof document.createRange undefined Try Mozilla's rangeOffset and rangeParent properties.. what we want if typeof evt.rangeParent undefined range document.createRange range.setStart evt.rangeParent evt.rangeOffset range.collapse.. var pos document.caretPositionFromPoint x y range document.createRange range.setStart pos.offsetNode pos.offset range.collapse true..
Persisting the changes of range objects after selection in HTML http://stackoverflow.com/questions/13949059/persisting-the-changes-of-range-objects-after-selection-in-html var saveSelection restoreSelection if window.getSelection document.createRange saveSelection function containerEl var range window.getSelection.. function containerEl savedSel var charIndex 0 range document.createRange range.setStart containerEl 0 range.collapse true var nodeStack..
Javascript Contenteditable - set Cursor / Caret to index http://stackoverflow.com/questions/16095155/javascript-contenteditable-set-cursor-caret-to-index contentEditableElement index var range selection if document.createRange Firefox Chrome Opera Safari IE 9 range document.createRange.. Firefox Chrome Opera Safari IE 9 range document.createRange Create a range a range is a like the selection but invisible.. setSelectionByCharacterOffsets null if window.getSelection document.createRange setSelectionByCharacterOffsets function containerEl start end..
HTML5 draggable elements within contenteditable div - stops working after first drop - why? http://stackoverflow.com/questions/16900032/html5-draggable-elements-within-contenteditable-div-stops-working-after-first e.clientX e.clientY else if e.rangeParent Firefox range document.createRange range.setStart e.rangeParent e.rangeOffset console.log 'range'..
Insert link in contenteditable element http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element if sel.getRangeAt sel.rangeCount linkRange document.createRange for var r 0 r sel.rangeCount r range sel.getRangeAt r containerEl..
how to get selection inside a div using jquery/javascript http://stackoverflow.com/questions/5801347/how-to-get-selection-inside-a-div-using-jquery-javascript rangeCount if rangeCount sel.rangeCount 0 var range document.createRange for var i 0 selRange i rangeCount i range.selectNodeContents..
How to set caret(cursor) position in contenteditable element (div)? http://stackoverflow.com/questions/6249095/how-to-set-caretcursor-position-in-contenteditable-element-div to button click but it doesn't work FF Chrome var range document.createRange var myDiv document.getElementById editable range.setStart myDiv.. var el document.getElementById editable var range document.createRange var sel window.getSelection range.setStart el.childNodes 2 5..
JQuery: Selecting Text in an Element (akin to highlighting with your mouse) http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse .browser.opera var selection window.getSelection var range document.createRange range.selectNodeContents text selection.removeAllRanges selection.addRange..
Text selection in div(contenteditable) when double click http://stackoverflow.com/questions/12920225/text-selection-in-divcontenteditable-when-double-click IE way first if document.body.createTextRange range document.body.createTextRange range.moveToPoint x y else if typeof document.createRange undefined Try Mozilla's rangeOffset and rangeParent properties which are exactly what we want if typeof evt.rangeParent.. rangeOffset and rangeParent properties which are exactly what we want if typeof evt.rangeParent undefined range document.createRange range.setStart evt.rangeParent evt.rangeOffset range.collapse true Try the standards based way next else if document.caretPositionFromPoint.. standards based way next else if document.caretPositionFromPoint var pos document.caretPositionFromPoint x y range document.createRange range.setStart pos.offsetNode pos.offset range.collapse true Next the WebKit way else if document.caretRangeFromPoint..
Persisting the changes of range objects after selection in HTML http://stackoverflow.com/questions/13949059/persisting-the-changes-of-range-objects-after-selection-in-html something like this Demo http jsfiddle.net WeWy7 3 Code var saveSelection restoreSelection if window.getSelection document.createRange saveSelection function containerEl var range window.getSelection .getRangeAt 0 var preSelectionRange range.cloneRange preSelectionRange.selectNodeContents.. start start end start range.toString .length restoreSelection function containerEl savedSel var charIndex 0 range document.createRange range.setStart containerEl 0 range.collapse true var nodeStack containerEl node foundStart false stop false while stop node..
Javascript Contenteditable - set Cursor / Caret to index http://stackoverflow.com/questions/16095155/javascript-contenteditable-set-cursor-caret-to-index s is a paragraph. I have this but with no luck function setCaret contentEditableElement index var range selection if document.createRange Firefox Chrome Opera Safari IE 9 range document.createRange Create a range a range is a like the selection but invisible.. contentEditableElement index var range selection if document.createRange Firefox Chrome Opera Safari IE 9 range document.createRange Create a range a range is a like the selection but invisible range.setStart contentEditableElement index range.collapse.. different again because it uses a different mechanism. var setSelectionByCharacterOffsets null if window.getSelection document.createRange setSelectionByCharacterOffsets function containerEl start end var charIndex 0 range document.createRange range.setStart..
HTML5 draggable elements within contenteditable div - stops working after first drop - why? http://stackoverflow.com/questions/16900032/html5-draggable-elements-within-contenteditable-div-stops-working-after-first Chrome range document.caretRangeFromPoint e.clientX e.clientY else if e.rangeParent Firefox range document.createRange range.setStart e.rangeParent e.rangeOffset console.log 'range' range var sel window.getSelection sel.removeAllRanges sel.addRange..
Insert link in contenteditable element http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element containerEl links linkRange if window.getSelection sel window.getSelection if sel.getRangeAt sel.rangeCount linkRange document.createRange for var r 0 r sel.rangeCount r range sel.getRangeAt r containerEl range.commonAncestorContainer if containerEl.nodeType..
how to get selection inside a div using jquery/javascript http://stackoverflow.com/questions/5801347/how-to-get-selection-inside-a-div-using-jquery-javascript typeof window.getSelection undefined var sel window.getSelection rangeCount if rangeCount sel.rangeCount 0 var range document.createRange for var i 0 selRange i rangeCount i range.selectNodeContents el selRange sel.getRangeAt i if selRange.compareBoundaryPoints..
How to set caret(cursor) position in contenteditable element (div)? http://stackoverflow.com/questions/6249095/how-to-set-caretcursor-position-in-contenteditable-element-div div. From searching over the web I have this JS attached to button click but it doesn't work FF Chrome var range document.createRange var myDiv document.getElementById editable range.setStart myDiv 5 range.setEnd myDiv 5 Is it possible to set manually caret.. fifth character of the second line of text you'd do the following var el document.getElementById editable var range document.createRange var sel window.getSelection range.setStart el.childNodes 2 5 range.collapse true sel.removeAllRanges sel.addRange range..
JQuery: Selecting Text in an Element (akin to highlighting with your mouse) http://stackoverflow.com/questions/985272/jquery-selecting-text-in-an-element-akin-to-highlighting-with-your-mouse text range.select else if .browser.mozilla .browser.opera var selection window.getSelection var range document.createRange range.selectNodeContents text selection.removeAllRanges selection.addRange range else if .browser.safari var selection window.getSelection..
|