How can I collapse selected text in a contentEditable div to the start of the selection , not the entire div?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For all major browsers except IE <= 8, you can use the
collapseToStart()method of the selection to collapse to the earliest point of the selection in document order, regardless of the direction of the selection:In IE <= 8, use the following, which is the equivalent of the first example above:
Finally, putting these together to make a cross-browser function:
Live demo: http://jsfiddle.net/yQS9G/2/