原生js增加,移除类名
2024-09-03 11:12:22
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box{width: 200px;height: 200px;background: yellowgreen}
.page{color: red}
.btn{font-size: 20px;}
</style>
</head>
<body> <div class="box">这是测试</div> <script>
var box=document.getElementsByClassName("box")[0]; box.className=box.className+" "+"page";//增加类名
box.classList.add("btn");//增加类名
box.classList.remove("btn");//移除类名
box.classList.item(1);//根据索引找类名
console.log(box.className);
console.log(box.classList.item(1)) </script>
</body>
</html>
最新文章
- EF6 连接Oracle 迁移数据错误解决方法
- 使用EntityFramework6.1的DbCommandInterceptor拦截生成的SQL语句
- Portable Operating System Interface for uni-X
- XPath学习:轴(14)——总结
- Apps Vol53
- python - 回溯继承树 - 自己实现
- C++学习笔记-2-构造函数和析构函数
- shell command使用技巧
- 关于@font-face的一些问题
- 详细介绍ASP.NET页面重定向方法
- cooking eggs
- Hbulider里面template模板自用
- [iOS]C语言知识点系列视频
- WinForm 对话框、流
- oracle sql 树操作
- Mysql 的 IF 判断
- 【持续跟新】剑指Offer_Java实现
- LDOOP ADD_PRINT_TEXT多页项
- Asp.net+WebSocket+Emgucv实时人脸识别
- POI导入工具类
热门文章
- OdDbAttribute和OdDbAttributeDefinition是什么关系
- JS规则 我还有其它用途( +号操作符)例如,算术操作符(+、-、*、/等),比较操作符(<;、>;、>;=、<;=等),逻辑操作符(&;&;、||、!)
- 接口测试——postman
- 北京服务业占GDP比重达81.7%
- 图书-技术-SpringBoot:《Spring Boot 企业级应用开发实战》
- iOS之UIButton的normal和selected状态切换
- Python基础---序列对象
- springcloud(十):Hystrix工作流程分析
- Linux文件句柄数配置
- 2018-11-26-win10-uwp-获取窗口的坐标和宽度高度