Created
December 8, 2017 13:55
-
-
Save sykwer/a8aba4f3a456cd509d966c1e165e5474 to your computer and use it in GitHub Desktop.
In contenteEditable div, wrap row by p tag when press enter key.
This file contains 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 node = document.getElementById("contenteditable-id") | |
node.addEventListener("keypress", (e) => { | |
if (e.keyCode === 13) { | |
document.execCommand("formatBlock", false, "p") | |
} | |
}) | |
// Wrap by h2 tag | |
// document.execCommand("formatBlock", false, "h2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment