| jquery Programming Glossary: document.selectionInserting a text where cursor is using Javascript/jquery http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery  br txtarea.selectionStart txtarea.selectionStart '0' ff document.selection ie false if br ie txtarea.focus var range document.selection.createRange.. ie false if br ie txtarea.focus var range document.selection.createRange range.moveStart 'character' txtarea.value.length.. strPos strPos text.length if br ie txtarea.focus var range document.selection.createRange range.moveStart 'character' txtarea.value.length.. 
 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  sel.removeAllRanges sel.addRange range else if document.selection saveSelection function containerEl var selectedTextRange document.selection.createRange.. saveSelection function containerEl var selectedTextRange document.selection.createRange var preSelectionTextRange document.body.createTextRange.. 
 How can I position an element next to user text selection? http://stackoverflow.com/questions/1589721/how-can-i-position-an-element-next-to-user-text-selection  .substr 2 var selectionEl return function var sel range if document.selection document.selection.createRange  Clone the TextRange and collapse.. return function var sel range if document.selection document.selection.createRange  Clone the TextRange and collapse range document.selection.createRange..  Clone the TextRange and collapse range document.selection.createRange .duplicate  range.collapse false  Create the marker.. 
 Javascript Highlight Selected Range Button http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button  colour  catch ex  makeEditableAndHighlight colour  else if document.selection document.selection.createRange IE 8 case range document.selection.createRange.. colour  else if document.selection document.selection.createRange IE 8 case range document.selection.createRange range.execCommand.. document.selection.createRange IE 8 case range document.selection.createRange range.execCommand BackColor false colour   share.. 
 Get Cursor Position within a Text Input field http://stackoverflow.com/questions/2897155/get-cursor-position-within-a-text-input-field  oField Initialize var iCaretPos 0 IE Support if document.selection Set focus on the element oField.focus To get cursor position.. To get cursor position get empty selection range var oSel document.selection.createRange Move selection start to 0 position oSel.moveStart.. 
 Clear Text Selection with JavaScript http://stackoverflow.com/questions/3169786/clear-text-selection-with-javascript  Firefox window.getSelection .removeAllRanges else if document.selection IE document.selection.empty Credit to Mr. Y.  share improve.. 
 Change CSS of selected text using Javascript http://stackoverflow.com/questions/3223682/change-css-of-selected-text-using-javascript  SelText document.getSelection else if document.selection SelText document.selection.createRange .text return SelText.. document.getSelection else if document.selection SelText document.selection.createRange .text return SelText However when I created a similar.. SelText document.getSelection else if document.selection SelText document.selection.createRange .text SelText .css 'background.. 
 Can I conditionally change the character entered into an input on keypress? http://stackoverflow.com/questions/3923089/can-i-conditionally-change-the-character-entered-into-an-input-on-keypress  this.selectionStart this.selectionEnd start 1 else if document.selection document.selection.createRange  For IE up to version 8 var selectionRange.. this.selectionEnd start 1 else if document.selection document.selection.createRange  For IE up to version 8 var selectionRange document.selection.createRange..  For IE up to version 8 var selectionRange document.selection.createRange  var textInputRange this.createTextRange  var precedingRange.. 
 Get the Highlighted/Selected text http://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text  text window.getSelection .toString else if document.selection document.selection.type Control text document.selection.createRange.. window.getSelection .toString else if document.selection document.selection.type Control text document.selection.createRange .text return.. 
 getSelection() not working in IE http://stackoverflow.com/questions/5421892/getselection-not-working-in-ie  to 9 doesn't support window.getSelection . You can use document.selection instead see this msdn page for the description . This selection.. works in IE '#click' .click function var range document.selection.createRange range.pasteHTML span style 'color red' range.htmlText.. 
 Insert link in contenteditable element http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element  i  ranges.push sel.getRangeAt i  return ranges  else if document.selection document.selection.createRange return document.selection.createRange.. i  return ranges  else if document.selection document.selection.createRange return document.selection.createRange return null.. document.selection document.selection.createRange return document.selection.createRange return null function restoreSelection savedSel if.. 
 get selected text's html in div http://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div  I case of IE i am able to get selected text html by using document.selection.createRange . But how can i find selected text html in FireFox... if document.getSelection t document.getSelection else if document.selection t document.selection.createRange .text return t function document.. t document.getSelection else if document.selection t document.selection.createRange .text return t function document .bind mouseup function.. 
 How do I detect “shift+enter” and generate a new line in Textarea? http://stackoverflow.com/questions/6014702/how-do-i-detect-shiftenter-and-generate-a-new-line-in-textarea  el if el.selectionStart return el.selectionStart else if document.selection el.focus var r document.selection.createRange if r null return.. else if document.selection el.focus var r document.selection.createRange if r null return 0 var re el.createTextRange rc.. 
 How to get selected(user-highlighted) text in contenteditable element and replace it? http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac  .cloneContents   html container.innerHTML  else if typeof document.selection undefined if document.selection.type Text  html document.selection.createRange..  else if typeof document.selection undefined if document.selection.type Text  html document.selection.createRange .htmlText  alert.. undefined if document.selection.type Text  html document.selection.createRange .htmlText  alert html Code taken from Tim Down Return.. 
 Insert html at caret in a contenteditable div http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div  true  sel.removeAllRanges  sel.addRange range   else if document.selection document.selection.type Control  IE 9 document.selection.createRange..  sel.addRange range   else if document.selection document.selection.type Control  IE 9 document.selection.createRange .pasteHTML.. document.selection document.selection.type Control  IE 9 document.selection.createRange .pasteHTML html  UPDATE 21 AUGUST 2013 As requested.. 
 Insert selected text on the page into textarea (jQuery) http://stackoverflow.com/questions/815202/insert-selected-text-on-the-page-into-textarea-jquery  if window.getSelection return window.getSelection else if document.selection return document.selection.createRange .text return ''   share.. 
 Inserting a text where cursor is using Javascript/jquery http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery  areaId var scrollPos txtarea.scrollTop var strPos 0 var br txtarea.selectionStart txtarea.selectionStart '0' ff document.selection ie false if br ie txtarea.focus var range document.selection.createRange range.moveStart 'character' txtarea.value.length.. br txtarea.selectionStart txtarea.selectionStart '0' ff document.selection ie false if br ie txtarea.focus var range document.selection.createRange range.moveStart 'character' txtarea.value.length strPos range.text.length else if br ff strPos txtarea.selectionStart.. strPos txtarea.value.length txtarea.value front text back strPos strPos text.length if br ie txtarea.focus var range document.selection.createRange range.moveStart 'character' txtarea.value.length range.moveStart 'character' strPos range.moveEnd 'character'.. 
 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  i  nodeStack.push node.childNodes i    var sel window.getSelection sel.removeAllRanges sel.addRange range else if document.selection saveSelection function containerEl var selectedTextRange document.selection.createRange var preSelectionTextRange document.body.createTextRange.. sel.addRange range else if document.selection saveSelection function containerEl var selectedTextRange document.selection.createRange var preSelectionTextRange document.body.createTextRange preSelectionTextRange.moveToElementText containerEl.. 
 How can I position an element next to user text selection? http://stackoverflow.com/questions/1589721/how-can-i-position-an-element-next-to-user-text-selection  markerId sel_ new Date .getTime _ Math.random .toString .substr 2 var selectionEl return function var sel range if document.selection document.selection.createRange  Clone the TextRange and collapse range document.selection.createRange .duplicate  range.collapse.. Date .getTime _ Math.random .toString .substr 2 var selectionEl return function var sel range if document.selection document.selection.createRange  Clone the TextRange and collapse range document.selection.createRange .duplicate  range.collapse false  Create.. function var sel range if document.selection document.selection.createRange  Clone the TextRange and collapse range document.selection.createRange .duplicate  range.collapse false  Create the marker element containing a single invisible character by creating.. 
 Javascript Highlight Selected Range Button http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button  BackColor false colour  makeEditableAndHighlight colour  catch ex  makeEditableAndHighlight colour  else if document.selection document.selection.createRange IE 8 case range document.selection.createRange range.execCommand BackColor false colour .. false colour  makeEditableAndHighlight colour  catch ex  makeEditableAndHighlight colour  else if document.selection document.selection.createRange IE 8 case range document.selection.createRange range.execCommand BackColor false colour   share improve this.. 
 Get Cursor Position within a Text Input field http://stackoverflow.com/questions/2897155/get-cursor-position-within-a-text-input-field  value range is 0 oField.value.length. function doGetCaretPosition oField Initialize var iCaretPos 0 IE Support if document.selection Set focus on the element oField.focus To get cursor position get empty selection range var oSel document.selection.createRange.. if document.selection Set focus on the element oField.focus To get cursor position get empty selection range var oSel document.selection.createRange Move selection start to 0 position oSel.moveStart 'character' oField.value.length The caret position is selection.. 
 Clear Text Selection with JavaScript http://stackoverflow.com/questions/3169786/clear-text-selection-with-javascript 
 Change CSS of selected text using Javascript http://stackoverflow.com/questions/3223682/change-css-of-selected-text-using-javascript  if window.getSelection SelText window.getSelection else if document.getSelection SelText document.getSelection else if document.selection SelText document.selection.createRange .text return SelText However when I created a similar function to change the CSS.. window.getSelection else if document.getSelection SelText document.getSelection else if document.selection SelText document.selection.createRange .text return SelText However when I created a similar function to change the CSS of the selected text using.. if window.getSelection SelText window.getSelection else if document.getSelection SelText document.getSelection else if document.selection SelText document.selection.createRange .text SelText .css 'background color' 'yellow' 'font weight' 'bolder' Any ideas .. 
 Can I conditionally change the character entered into an input on keypress? http://stackoverflow.com/questions/3923089/can-i-conditionally-change-the-character-entered-into-an-input-on-keypress  val.slice 0 start mappedChar val.slice end  Move the caret this.selectionStart this.selectionEnd start 1 else if document.selection document.selection.createRange  For IE up to version 8 var selectionRange document.selection.createRange  var textInputRange.. mappedChar val.slice end  Move the caret this.selectionStart this.selectionEnd start 1 else if document.selection document.selection.createRange  For IE up to version 8 var selectionRange document.selection.createRange  var textInputRange this.createTextRange.. start 1 else if document.selection document.selection.createRange  For IE up to version 8 var selectionRange document.selection.createRange  var textInputRange this.createTextRange  var precedingRange this.createTextRange  var bookmark selectionRange.getBookmark.. 
 Get the Highlighted/Selected text http://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text 
 getSelection() not working in IE http://stackoverflow.com/questions/5421892/getselection-not-working-in-ie  internet explorer   share improve this question   IE prior to 9 doesn't support window.getSelection . You can use document.selection instead see this msdn page for the description . This selection object has a method createRange that returns a TextRange.. www.quirksmode.org dom range_intro.html . The following implementation works in IE '#click' .click function var range document.selection.createRange range.pasteHTML span style 'color red' range.htmlText span It's not nearly as nice as the other implementation.. 
 Insert link in contenteditable element http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element   var ranges  for var i 0 len sel.rangeCount i len i  ranges.push sel.getRangeAt i  return ranges  else if document.selection document.selection.createRange return document.selection.createRange return null function restoreSelection savedSel if savedSel..  for var i 0 len sel.rangeCount i len i  ranges.push sel.getRangeAt i  return ranges  else if document.selection document.selection.createRange return document.selection.createRange return null function restoreSelection savedSel if savedSel if window.getSelection.. i len i  ranges.push sel.getRangeAt i  return ranges  else if document.selection document.selection.createRange return document.selection.createRange return null function restoreSelection savedSel if savedSel if window.getSelection  sel window.getSelection .. 
 get selected text's html in div http://stackoverflow.com/questions/5669448/get-selected-texts-html-in-div  able to get selected text in FireFox by window.getSelection I case of IE i am able to get selected text html by using document.selection.createRange . But how can i find selected text html in FireFox. How can in do this.Please help.  javascript jquery   share.. var t '' if window.getSelection t window.getSelection else if document.getSelection t document.getSelection else if document.selection t document.selection.createRange .text return t function document .bind mouseup function var mytext x.Selector.getSelected.. t window.getSelection else if document.getSelection t document.getSelection else if document.selection t document.selection.createRange .text return t function document .bind mouseup function var mytext x.Selector.getSelected alert mytext  Check.. 
 How do I detect “shift+enter” and generate a new line in Textarea? http://stackoverflow.com/questions/6014702/how-do-i-detect-shiftenter-and-generate-a-new-line-in-textarea  Ref How to get caret position in textarea function getCaret el if el.selectionStart return el.selectionStart else if document.selection el.focus var r document.selection.createRange if r null return 0 var re el.createTextRange rc re.duplicate re.moveToBookmark.. textarea function getCaret el if el.selectionStart return el.selectionStart else if document.selection el.focus var r document.selection.createRange if r null return 0 var re el.createTextRange rc re.duplicate re.moveToBookmark r.getBookmark rc.setEndPoint.. 
 How to get selected(user-highlighted) text in contenteditable element and replace it? http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac  i len i  container.appendChild sel.getRangeAt i .cloneContents   html container.innerHTML  else if typeof document.selection undefined if document.selection.type Text  html document.selection.createRange .htmlText  alert html Code taken from Tim.. sel.getRangeAt i .cloneContents   html container.innerHTML  else if typeof document.selection undefined if document.selection.type Text  html document.selection.createRange .htmlText  alert html Code taken from Tim Down Return HTML from a user selection..   html container.innerHTML  else if typeof document.selection undefined if document.selection.type Text  html document.selection.createRange .htmlText  alert html Code taken from Tim Down Return HTML from a user selection  share improve this answer.. 
 Insert html at caret in a contenteditable div http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div  range.cloneRange  range.setStartAfter lastNode  range.collapse true  sel.removeAllRanges  sel.addRange range   else if document.selection document.selection.type Control  IE 9 document.selection.createRange .pasteHTML html  UPDATE 21 AUGUST 2013 As requested.. lastNode  range.collapse true  sel.removeAllRanges  sel.addRange range   else if document.selection document.selection.type Control  IE 9 document.selection.createRange .pasteHTML html  UPDATE 21 AUGUST 2013 As requested in the comments here.. true  sel.removeAllRanges  sel.addRange range   else if document.selection document.selection.type Control  IE 9 document.selection.createRange .pasteHTML html  UPDATE 21 AUGUST 2013 As requested in the comments here is an updated example with an extra.. 
 Insert selected text on the page into textarea (jQuery) http://stackoverflow.com/questions/815202/insert-selected-text-on-the-page-into-textarea-jquery 
 |