Cross Browser Javascript Code to Get/Set Caret Position in Textarea/Input
Note: In year 2021, this solution still works for textarea/input. Here is a working snippet of code to get and set the caret position in HTML textarea and textbox. This code works for IE 6, 7, 8, >=9, Edge, Chrome, Safari, Firefox and Opera.