I want to select all the text in contenteditable element when focusing and not on clicking. Tab should trigger the selection here. I found this approach select all text in contenteditable div when it focus/click but that is on clicking which does not work for tab and does not let the user to select part of the text.
In the link provided I tried onfocus
instead of onclick
and surprisingly does not work.
Asked
Active
Viewed 671 times
1

Community
- 1
- 1

Sami Al-Subhi
- 4,406
- 9
- 39
- 66
-
What have you tried? Typically, you need to show your specific attempts (with code), in order to get a good answer. – htxryan Aug 29 '13 at 01:24
-
If you look at the answer in the link you provided you will see a comment by user "Rudie". Rudie solved the onfocus issue by delaying execution of the select using requestAnimationFrame. You could probably achieve a similar result with `setTimeout` in your `onfocus` handler. – veritasetratio Aug 29 '13 at 01:29
-
http://jsfiddle.net/kfypq/2/ It does not work with `setTimeout` – Sami Al-Subhi Aug 29 '13 at 01:39
-
You are calling document.execCommand. Look more closely at Rudie's example. – veritasetratio Aug 29 '13 at 02:24
-
http://jsfiddle.net/kfypq/4/ one thing remained which is when focusing the element using tab, the function should not `preventDefault()` of `mouseup` – Sami Al-Subhi Aug 29 '13 at 06:02
-
Did you try [my answer to that question](http://stackoverflow.com/a/3806004/96100)? – Tim Down Aug 29 '13 at 08:47
-
@TimDown It works exactly how I want it. Thank you so much. – Sami Al-Subhi Aug 29 '13 at 09:29