Skip to content

Instantly share code, notes, and snippets.

@egorguscha
Created September 8, 2020 13:25
Show Gist options
  • Save egorguscha/21be6e382f98f48c019f3b1247048be7 to your computer and use it in GitHub Desktop.
Save egorguscha/21be6e382f98f48c019f3b1247048be7 to your computer and use it in GitHub Desktop.
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