Search code examples
javascriptinternet-explorer-10

Clearing innerHTML trouble in IE10


Here is my function:

    swPageProt.showContent = function () {
        if (this._Parent) {
            var container = this._Parent.getContentNode();
            if (container) {
                console.log(this._Content.innerHTML);
                console.log(this._Parent.getContentNode().innerHTML);
                container.innerHTML = '';
                if (this._Content instanceof WT.BaseControl) {
                    this._Content.addToNode(container);
                }
                else if (this._Content.tagName) {
                    console.log(this._Content.innerHTML);
                    console.log(this._Parent.getContentNode().innerHTML);
                    container.appendChild(this._Content);
                }
                else {
                    container.innerHTML = this._Content + '' || '';
                }
            }
        }
    };

I want to clear parent container and append this._Content to it. This works fine in Chrome and Firefox, but the line container.innerHTML = ''; clears both parent and this instances in IE10. And I always get empty parent container with empty child (this) content. How to fix it in IE10?


Solution

  • Solution found! It's necessary to use container.removeChild(container.firstChild); instead of container.innerHTML = '';