Capturing "move cursor" events inside text areas using jQuery (compatible with IE6)

How can I catch the "change cursor position" event inside textarea using jquery (should also work in IE6)?

example1

before: text |

after: te |

example2

before: text |

after: text tex | t2

example3

before: text |

after: |


Edit

After detecting the cursor event, you must also check to see if the cursor changes its position (also work for ie6)

Edit2

If you have a solution that will not work in ie6, but in ie7 + webkit, write it

Thanks,

Yosef

+7
source share
1 answer

There are essentially three events that can cause the cursor to change position,

  • keystrokes
  • mouse clicks
  • software events such as insert, select, focus ...

    I would capture these events for what you are trying to accomplish using "change cursor position"

code sample added:

$("#myTextInput").bind("keydown click focus", function() { alert("Current position: " + $(this).caret().start); }); 

Thanks @Nick Craver

+15
source

All Articles