How to dynamically change CSS class of DIV tag?

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

    You should use:

        boolVal.onchange=function(){
                    document.getElementById("MyElement").className = boolVal ? "redClass" : "blueClass";
        };
    

提交回复
热议问题