21 June 2016

Using selectionStart, selectionEnd, setSelectionRange in jQuery example. You can't use DOM commands on jQuery objects directly, you have to get the first value of the object.

Source code viewer
  1. // Store current positions in variables.
  2. var selectionStart = $('input')[0].selectionStart;
  3. var selectionEnd = $('input')[0].selectionEnd;
  4.  
  5. // Restore from variables.
  6. $('input')[0].setSelectionRange(selectionStart, selectionEnd);
Programming Language: jQuery