classList
-
前言
classList方法可以获取到这个dom元素的类的对象,但是目前classList属性只有FireFox3.6+和Chrome支持。
- add(value) —— 添加一个类
- contains(value) —— 判断有没有某个类
- remove(value) —— 删除一个类
- toggle(value) —— 切换一个类
- replace() —— 替换一个类
Style
<style type="text/css"> #box { border: 1px red solid; width: 400px; height: 400px; } #box.add_color{ background-color: #33CCFF; } #box.add_border{ border: 2px deeppink solid; } .aa{ background-color: #666ccc; } </style>
Html
<body> <div id="box"></div><br><br> <input type="button" value="增加"> <input type="button" value="删除"> <input type="button