Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a jQuery plugin that will allow you to do @username style tags, like Facebook does in their status update input box.
My problem is, that even after hours of researching and experimenting, it seems REALLY hard to simply move the caret.

I've managed to inject the @tag with someone's name, but placing the caret after it seems like rocket science, specially if it's supposed work in all browsers.
And I haven't even looked into replacing the typed @username text with the tag yet, rather than just injecting it as I'm doing right now.

There's a ton of questions about working with contenteditable on Stack Overflow & google so much contents, and I think I've read all of them, but they don't really cover properly what I need. So any more information anyone can provide would be great :)
Posted
Updated 30-Jul-10 1:21am
v3

1 solution

Don't hem yourself in with jQuery, straight-up JavaScript will work fine.

Here's a snippet on setting the cursor position:
Get/Set Cursor position in textbox by Javascript

Hope this helps.

Cheers.

btw: for removing the @username, just do a string replace prior to figuring out where you're setting the cursor location.
 
Share this answer
 
Comments
Shilpi@Live 2-Aug-10 2:35am    
Thanks for the answer.

what is caretpos in the function setCaretPosition(elemId, caretPos)pls reply soon.

Shilpi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900