How to dynamically change the style tag using JavaScript?

前端 未结 9 2164
走了就别回头了
走了就别回头了 2021-01-01 21:50

I want to change the style tag after generating contents. How can I add style to the style tag? I tried using:

document.getElementById(\'style\').appendChil         


        
9条回答
  •  抹茶落季
    2021-01-01 22:21

    style is a property. After you getElementById() you can change its style.

    HTML:

    ...

    JS:

    var div = document.getElementById('myDiv')
    
    div.style.background = 'red';
    div.style.margin = "10px";
    div.style.fontSize = "12px";
    

    etc.

提交回复
热议问题