How to dynamically change CSS class of DIV tag?

前端 未结 6 1245
离开以前
离开以前 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:17

    Something like this:

    document.getElementById("MyElement").className = boolVal ? "redClass" : "blueClass";
    

提交回复
热议问题