I am using JavaScript. I have a variable var boolVal
that either evaluates to true
/false
. On my page, I have a <div>
tag:
<div id='div1' class="redClass"></div>
Based on the value of var boolVal
, I want to change the CSS class of the <div>
tag to blueClass
.
For example: present class makes <div>
color red, then the new class should make the page blue at runtime without need for page refresh.
Can we achieve this in simple JavaScript? Can we use
document.getElementById("MyElement").className = "MyClass";
or should we use AddClass
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…