Created
April 19, 2018 08:53
-
-
Save tonis2/91c24ac8b8b9274665b22a9659d39b8d to your computer and use it in GitHub Desktop.
contentEditable insert element and focus behind it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const container = document.querySelector(".pell-content"); | |
| let selection = window.getSelection(); | |
| let range = selection.getRangeAt(0); | |
| let dom = HTML`<div id="node"><span style="color:red">${selection.toString()}</span></div>`; | |
| selection.deleteFromDocument(); | |
| range.insertNode(dom); | |
| ///Insert first node | |
| range.setStartAfter(dom); | |
| range.setEndAfter(dom); | |
| selection.removeAllRanges(); | |
| selection.addRange(range); | |
| //Focus behind it. | |
| range.insertNode(HTML`<span>Iöötab raisk</span>`); | |
| //Insert next node. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment