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
// Store current positions in variables. var selectionStart = $('input')[0].selectionStart; var selectionEnd = $('input')[0].selectionEnd; // Restore from variables. $('input')[0].setSelectionRange(selectionStart, selectionEnd);Programming Language: jQuery