LoginSignup
0
1

More than 5 years have passed since last update.

styleタグをjsから動的に書き換える

Last updated at Posted at 2018-09-07

codepen的なもの
入力されたcssを即時反映する処理をjquery無しで書く

const old = document.getElementById('inserted-style')
old && old.parentNode.removeChild(old)
const obj = document.createElement('style')
obj.setAttribute('id', 'inserted-style')
obj.appendChild(document.createTextNode(埋め込みたいcss))
document.getElementsByTagName('head')[0].appendChild(obj)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1