forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject-style.js
More file actions
33 lines (28 loc) · 813 Bytes
/
inject-style.js
File metadata and controls
33 lines (28 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
let styleSheet;
function injectStyle(style) {
if (styleSheet && styleSheet.parentNode) {
// append the style to the existing sheet
if (styleSheet.styleSheet === undefined) {
// Not old IE
styleSheet.appendChild(document.createTextNode(style));
} else {
styleSheet.styleSheet.cssText += style;
}
return styleSheet;
}
if (!style) {
return;
}
const head = document.head || document.getElementsByTagName('head')[0];
styleSheet = document.createElement('style');
styleSheet.type = 'text/css';
if (styleSheet.styleSheet === undefined) {
// Not old IE
styleSheet.appendChild(document.createTextNode(style));
} else {
styleSheet.styleSheet.cssText = style;
}
head.appendChild(styleSheet);
return styleSheet;
}
export default injectStyle;