如何删除添加到div的当前类,并根据条件集添加新的类?删除当前的css类和使用jquery添加新的类
我的CSS包含3次不同的类别:在我要添加只有一个等级符合条件的jQuery变量my_color
设置为div的ID #box
时间
.red { background:red }
.blue { background:blue }
.green { background:green }
。 my_color
有3个值血,花园,天空当时只有一组。
的jQuery:
<script type="text/javascript">
(document).ready(function() {
if(my_color == "blood")
{ /*help me to remove current class and add .red */}
else if(my_color == "garden")
{/*help me to remove current class and add .green */ }
else if(my_color == "sky")
{/*help me to remove current class and add .blue */ }
});
</script>
其删除不需要的类看起来像前一个回答http://stackoverflow.com/a/14685691/1957479 –