I have several a elements within a contenteditable div
. How can I place the keyboard caret at the end of a specific element identified by id and later move it to the end of the div
using Rangy?
Thanks in advance and any help appreciated.
I have several a elements within a contenteditable div
. How can I place the keyboard caret at the end of a specific element identified by id and later move it to the end of the div
using Rangy?
Thanks in advance and any help appreciated.
Copyright © 2021 Jogjafile Inc.
To set the caret after a specific element, you'll want to create a range and apply that range to the browser's selection object, as follows:
At some point if you wish to move the caret then you'd do the same thing as above to move it after the 'DIV', although if you wish the selection range to go from after your 'A' tag to the after your 'DIV' tag then you'd do this:
If you want your selection to be at the end of an element, but inside the element instead of after the element then you would do something like this.
A few important notes: