Created
September 8, 2020 13:25
-
-
Save egorguscha/21be6e382f98f48c019f3b1247048be7 to your computer and use it in GitHub Desktop.
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
function css(tags, ...attrs) { | |
const value = style(tags, ...attrs) | |
const node = document.createElement('style') | |
node.id = 'insertedStyle' | |
node.appendChild(document.createTextNode(value)) | |
const sheet = document.getElementById('insertedStyle') | |
if (sheet) { | |
sheet.disabled = true | |
sheet.parentNode.removeChild(sheet) | |
} | |
document.head.appendChild(node) | |
function style(tags, ...attrs) { | |
if (tags.length === 0) return '' | |
let result = ' ' + tags[0] | |
for (let i = 0; i < attrs.length; i++) { | |
result += attrs[i] | |
result += tags[i + 1] | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment