Skip to content

Instantly share code, notes, and snippets.

@ktkaushik
Created January 13, 2016 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktkaushik/c0954dfd60369c1b138e to your computer and use it in GitHub Desktop.
Save ktkaushik/c0954dfd60369c1b138e to your computer and use it in GitHub Desktop.
Split text among nodes in POJS.
var node = Util.getSelectionStart()
var text = p.childNodes[0];
var at = 5;
// create new span node with content
var span = document.createElement("span");
span.appendChild(document.createTextNode('ipsum'));
// Split the text node into two and add new span
p.insertBefore(span, text.splitText(at));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment