Note that there are some explanatory texts on larger screens.

plurals
  1. POInconsistent Whitespace Text Nodes in Internet Explorer
    text
    copied!<p>The following source code alerts the following results:</p> <p><strong>Internet Explorer 7</strong>: 29<br> <strong>Firefox 3.0.3</strong>: 37 (correct)<br> <strong>Safari 3.0.4 (523.12.9)</strong>: 38<br> <strong>Google Chrome 0.3.154.9</strong>: 38 </p> <p>Please ignore the following facts: </p> <ul> <li>Webkit (Safari/Chrome) browsers insert an extra text node at the end of the body tag</li> <li>Internet Explorer doesn't have new lines in their whitespace nodes, like they should.</li> <li>Internet Explorer has no beginning whitespace node (there is obvious whitespace before the &lt;form&gt; tag, but no text node to match) </ul> <p>Of the tags in the test page, the following tags have no whitespace text nodes inserted in the DOM after them: <code>form</code>, <code>input[@radio]</code>, <code>div</code>, <code>span</code>, <code>table</code>, <code>ul</code>, <code>a</code>.</p> <p>My question is: <strong>What is it about these nodes that makes them the exception in Internet Explorer?</strong> Why is whitespace not inserted after these nodes, and is inserted in the others? </p> <p>This behavior is the same if you switch the tag order, switch the doctype to XHTML (while still maintaining standards mode).</p> <p>Here's a <a href="http://www.howtocreate.co.uk/wrongWithIE/?chapter=Empty+Space" rel="noreferrer">link that gives a little background information</a>, but no ideal solution. There might not be a solution to this problem, I'm just curious about the behavior.</p> <p>Thanks Internet, Zach</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;script type="text/javascript"&gt; function countNodes() { alert(document.getElementsByTagName('body')[0].childNodes.length); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="countNodes()"&gt; &lt;form&gt;&lt;/form&gt; &lt;input type="submit"/&gt; &lt;input type="reset"/&gt; &lt;input type="button"/&gt; &lt;input type="text"/&gt; &lt;input type="password"/&gt; &lt;input type="file"/&gt; &lt;input type="hidden"/&gt; &lt;input type="checkbox"/&gt; &lt;input type="radio"/&gt; &lt;button&gt;&lt;/button&gt; &lt;select&gt;&lt;/select&gt; &lt;textarea&gt;&lt;/textarea&gt; &lt;div&gt;&lt;/div&gt; &lt;span&gt;&lt;/span&gt; &lt;table&gt;&lt;/table&gt; &lt;ul&gt;&lt;/ul&gt; &lt;a&gt;&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload