Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

From How to preserve text selection when opening a jQuery dialogHow to preserve text selection when opening a jQuery dialog: you have to preserve selection on blur and restore it on focus:

$("dialog").focus(function() { // save the selection }).blur(function() { // set the text selection }); 

Setting selection (from jQuery Set Cursor Position in Text AreajQuery Set Cursor Position in Text Area):

$.fn.selectRange = function(start, end) { return this.each(function() { if(this.setSelectionRange) { this.focus(); this.setSelectionRange(start, end); } else if(this.createTextRange) { var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } }); }; $('#elem').selectRange(3,5); 

Getting selection: http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html

From How to preserve text selection when opening a jQuery dialog: you have to preserve selection on blur and restore it on focus:

$("dialog").focus(function() { // save the selection }).blur(function() { // set the text selection }); 

Setting selection (from jQuery Set Cursor Position in Text Area):

$.fn.selectRange = function(start, end) { return this.each(function() { if(this.setSelectionRange) { this.focus(); this.setSelectionRange(start, end); } else if(this.createTextRange) { var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } }); }; $('#elem').selectRange(3,5); 

Getting selection: http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html

From How to preserve text selection when opening a jQuery dialog: you have to preserve selection on blur and restore it on focus:

$("dialog").focus(function() { // save the selection }).blur(function() { // set the text selection }); 

Setting selection (from jQuery Set Cursor Position in Text Area):

$.fn.selectRange = function(start, end) { return this.each(function() { if(this.setSelectionRange) { this.focus(); this.setSelectionRange(start, end); } else if(this.createTextRange) { var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } }); }; $('#elem').selectRange(3,5); 

Getting selection: http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html

Source Link
Nickolay
  • 32.5k
  • 13
  • 111
  • 195

From How to preserve text selection when opening a jQuery dialog: you have to preserve selection on blur and restore it on focus:

$("dialog").focus(function() { // save the selection }).blur(function() { // set the text selection }); 

Setting selection (from jQuery Set Cursor Position in Text Area):

$.fn.selectRange = function(start, end) { return this.each(function() { if(this.setSelectionRange) { this.focus(); this.setSelectionRange(start, end); } else if(this.createTextRange) { var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } }); }; $('#elem').selectRange(3,5); 

Getting selection: http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html