Skip to content

Instantly share code, notes, and snippets.

@mailtruck
Forked from clauswitt/ClickToSplit.js
Created October 4, 2012 23:22
Show Gist options
  • Save mailtruck/3837089 to your computer and use it in GitHub Desktop.
Save mailtruck/3837089 to your computer and use it in GitHub Desktop.
Click to Split
function onclick(e) {
var range;
if (document.caretRangeFromPoint) {
range = document.caretRangeFromPoint(e.pageX, e.pageY);
} else if (e.rangeParent) {
range = document.createRange();
range.setStart(e.rangeParent, e.rangeOffset);
}
var textContainer = range.startContainer;
var node = textContainer.parentNode;
var origValue = node.innerHTML;
var textToKeep = origValue.substr(0, range.startOffset);
var textToMove = origValue.substr(range.startOffset);
node.innerHTML = textToKeep;
//Do something with textToMove
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment