LoginSignup
0

要素にまとめてstyleを追加、変更

Last updated at Posted at 2023-05-27

今まで使ってたのは

div.style.color = 'cyan'
div.style.fontSize = '14px'

一つずつ div.styleの続きを変えてたけど

div.setAttribute('style','color:cyan','font-size:14px')

element.setAttributeを使って一括で、cssに近い形でstyleを書ける

<div style = 'color:cyan;font-size:14px'> </div>

つまりこうなる

追記
style.cssTextってものがあるらしい
なにそれ便利すぎるでしょ

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