I just saw html5shiv and found this code:
function addStyleSheet(ownerDocument, cssText) {
var p = ownerDocument.createElement('p'),
parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
p.innerHTML = 'x<style>' + cssText + '</style>';
return parent.insertBefore(p.lastChild, parent.firstChild);
}
Where p.innerHTML = 'x<style>' + cssText + '</style>';
is used. Why x is used here?
No, this is not a typo.
According to question about x aFarkas has made answer
This is because of a non standard concept of old IE. Similiar to the concept of "has layout" in CSS, they had the concept of scoped and nonscoped elements for rendering with innerHTML.
When IE converts a string of HTML into a DOM structure, it treats SCRIPT and STYLE differently than any other tags. When it hits one, it checks to see if there are any nodes before it that are “visible.” (Visible very loosely means nodes that will be displayed when the structure is rendered.) If there aren’t any visible nodes before it hits SCRIPT or STYLE, it simply tosses those away and continues processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With