How to dynamically change CSS class of DIV tag?

前端 未结 6 1212
离开以前
离开以前 2020-12-15 04:55

I am using JavaScript. I have a variable var boolVal that either evaluates to true/false. On my page, I have a div tag.

<
6条回答
  •  無奈伤痛
    2020-12-15 05:26

    You can edit inline styles on a DOM element like so (height in this example):

    document.getElementById("element").style.height = height + "px";
    

    Basic syntax is:

    document.getElementById("div1").style.[style property] = [value];
    

    Syntax for the style property can vary and might not be exactly what it is in a CSS file. For example, background-color in a CSS file would be 'backgroundColor` in the above example.

提交回复
热议问题