wilsonpage
wilsonpage

Reputation: 17610

Javascript/jQuery : Refocus a contenteditable div that has child elements within

My Aim: I am detecting hash tags within a content editable field as they are typed. I want to be able to remove a hash tag a it is typed, append it to another container and refocus selection on the contenteditable div as if nothing happened.

My Problem: This works so long as there are no child elements within the contenteditable div but focus is not restored if there are children. I think I need an advanced method of focusing the caret. This has only been tested in Chrome so far.

My Example: http://jsbin.com/owoto4/5/edit

Help greatly appreciated!

Upvotes: 1

Views: 841

Answers (1)

wilsonpage
wilsonpage

Reputation: 17610

I may have cracked it by using code from this post: contenteditable, set caret at the end of the text (cross-browser)

See my example now: http://jsbin.com/owoto4/5/edit

Upvotes: 1

Related Questions