Last active
January 19, 2017 01:25
-
-
Save valdrinkoshi/4a92f97169a6fc41a1852f23211b8c4e to your computer and use it in GitHub Desktop.
IE11/Edge cloned stylesheets not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div { background-color: blue; color: white; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style id="myStyle"> div { background-color: red; } </style> | |
</head> | |
<body> | |
<div>I should have red background color, and after 1 second a white text color.</div> | |
<script> | |
setTimeout(function() { | |
// Link hosted in another node breaks the cascading order. | |
var div = document.createElement('div'); | |
div.innerHTML = '<link rel="stylesheet" href="blue.css">'; | |
var el = div.firstElementChild; | |
// Even if we clone it, it breaks the cascading order. | |
div.removeChild(el); | |
el = el.cloneNode(true); | |
// A new link w/o any parent works fine. | |
// Doesn't work for styles contained in <body>. | |
// el = document.createElement('link'); | |
// el.setAttribute('rel', 'stylesheet'); | |
// el.setAttribute('href', 'blue.css'); | |
myStyle.parentNode.insertBefore(el, myStyle); | |
}, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment