I am attempting to create a simple texteditor with HTML5 contenteditable on a div tag. As you know, selected text is handled quite differently in IE.
this.retrieveAnchorNode = function() {
var anchorNode;
if (document.selection)
anchorNode = document.selection.createRange().parentElement();
else if (document.getSelection)
anchorNode = window.getSelection().anchorNode;
}
I am looking for a way to get the selected textnode (not the text itself), like I can do with “anchorNode” and “focusNode” on other browsers. The only alternative on IE I have found is the “parentElement()” function, which only manages to select the contenteditable div itself.
Any ideas?
Here’s my version of the function you need from IERange, with my comments: