Raynos/DOM-shim — Issue #11: Add workaround for broken splitText() in IE9
Author: timdown
Created: 2011-10-22 15:46:54+00:00
State: open

Here's a Stack Overflow question illustrating the problem:

http://stackoverflow.com/questions/7378186/ie9-childnodes-not-updated-after-splittext

I cam across this problem independently. Here's my workaround:

function insertAfter(node, precedingNode) {
var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
if (nextNode) {
parent.insertBefore(node, nextNode);
} else {
parent.appendChild(node);
}
return node;
}

// Note that we cannot use splitText() because it is bugridden in IE 9.
function splitDataNode(node, index) {
var newNode = node.cloneNode(false);
newNode.deleteData(0, index);
node.deleteData(index, node.length - index);
insertAfter(newNode, node);
return newNode;
}