IE 9, 10, 11 Failing to Render Content of One Particular DIV (Added Using JS)

html, internet-explorer, javascript

Solution

This turns out to be a result of having the CSS selector:

#MultiSetup:empty { display: none; }

Apparently, IE 9+ continues to apply the `:empty` selector properties when the element ceases to be empty, so it remains hidden. When an element in the DOM tree is clicked it must cause some internal revalidation which then ceases to apply the properties.

Removing this selector resolves the problem (as does executing an explicit change when the innerHTML is set).

Problem

I am having a strange problem with IE 11 and IE 10 (and IE 10 and IE 9 using IE 11's compatibility rendering) whereby one particular `div` is not being rendered until and unless I open the developer tools and click on any tag in the DOM explorer. Once I do that the `div` contents are immediately rendered. The page in question renders correctly on all versions of Chrome, Firefox and on IE 5, 6, 7 and 8. [EDIT: IE6 not tested; and 5, 7 and 8 tested via IE 11's document rendering emulation modes]. The page is authenticated and part of a complex SPA client with the majority of the HTML generated using JS, and what is delivered from the server is a bare outline where the sidebar content (which contains the non-rendered `div`) is simply: ``` <div id="Top" onclick="RpA.reload()" title="..." style="visibility: hidden; cursor: pointer;"> <img src="images/blank.gif"/> </div> <div id="LibraryList"> </div> <div id="LogoutWrapper"> <input class="LogoutButton" type="button" value="Log out" onclick="RpA.logout();"/> </div> ``` and it's the first `div` block within the "LibraryList" which is not rendered, though the following (quite complex) table is. After JS manipulation the content of "LibraryList" is: ``` <div id="LibraryList" data-RpA_ListName="Library"> <div id="MultiSetup"> <div class="DefaultSetup" id="MultiSetup_ImageWrap"> <img src="/.../kingkong6.gif"> </div> <div id="MultiSetup_Text"> <a href="javascript:RpA.MultiSetup.edit_selBlock_start();">switch setup</a> <b>Default Setup</b> <br> </div> </div> <table cellspacing="0" cellpadding="0"> ... </table> </div> ``` While the JS is too complex in it's entirety to post here, it boils down to resolving the details via AJAX, finding the container `div` element and then injecting the resolved template using: ``` ele.innerHTML=Tpl.get("MultiSetup_Wrap").toString(stpobj,addobj); ``` Since the block renders immediately I try to examine the DOM, I can't be totally certain, but everything about the HTML and CSS is exactly as I expect and I can find no reason there why the block is not displayed. So far I seem to have eliminated timing and sequencing, that is, it doesn't seem to matter where in the long sequence of page content generation I put this particular `div` snippet, nor does it seem to be affected by client or server hardware speed. Any suggestions or advice on how to proceed from here? Update 1: If I do a deferred `show()` on the element using jQuery, it does display after the timeout (of any length - I've tried 1, 100, 500 and 1000 ms); for example: ``` setTimeout(function(){$("#MultiSetup").show()},1000); ``` Update 2: OK, so I have pinned this down to the fact that the enclosing `div` has CSS `display:none;` set in IE 9+, but not in Chrome, Firefox or IE 8-. And as soon as I click on an element in the DOM tree it's magically changed to `display:block`. Looking like an out and out bug in IE to me.

Original source