I am facing a strange problem with dynamically replacing controls using javascript in Google Chrome. The replaced controls dont show up in UI but when i use developer tools i am able to locate the replaced element but it does not show up until i close the developer tools. once i open and close developer tools the issue is no longer replicatable until i refresh the page.
This happens only in cases where i am trying to replace outerHTML of an element.
I first tried using jquery's replaceWith
api, that dint help so i switched to the following script -
function chromeOuterHTML(oldElem, outerhtml)
{
var el = document.createElement('div');
el.innerHTML = outerhtml;
var parentNode = oldElem.parentNode;
var range = document.createRange();
range.selectNodeContents(el);
var documentFragment = range.extractContents();
parentNode.insertBefore(documentFragment, oldElem);
parentNode.removeChild(oldElem);
}
I dont think that its a problem with my javascript since the problem is specific to chrome and also happens in only certain cases.
Any help would be greatly appreciated