Is it a typo in html5shiv?

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 is p.innerHTML = 'x<style>' + cssText + '</style>'; . Why is x used here?

+6
source share
1 answer

No, this is not a typo.

According to the question about x aFarkas made an answer

This is due to the non-standard concept of old IE. Most familiar with the “has layout” concept in CSS, they had the concept of covered and unverified elements for rendering using innerHTML.

aFarkas points to two articles

Problem

When IE converts an HTML string into a DOM structure, it processes SCRIPT and STYLE differently than any other tags. When he reaches one, he checks to see if there are any nodes in front of him that are "visible." (Seen very weakly means the nodes that will be displayed when rendering the structure.) If there are no visible nodes before the visible nodes before SCRIPT or STYLE, they just drop them and continue to process them.

+3
source

Source: https://habr.com/ru/post/972687/


All Articles