当前位置:网站首页>[JS adds attributes to elements: setAttribute; classlist.remove; classlist.add;]
[JS adds attributes to elements: setAttribute; classlist.remove; classlist.add;]
2022-07-01 01:41:00 【Min_ Fox】
- Get the current element first
html
<img id="zi" class="zi" src="/src/image/w.png">
js
const zi = document.getElementById("zi");
- modify img Elemental src attribute
Use setAttribute To set properties .
js
zi.setAttribute("src", this.key);
- Add to element class
Use classList.remove To delete class、classList.add To add new class, Can be used to modify the style .
js
// Delete class
zi.classList.remove("update-file-block");
// increase class
zi.classList.add("update-file-none");
css
.update-file-block {
display: inline-block;
}
.update-file-none {
display: none !important;
}
边栏推荐
- For the sustainable development of software testing, we must learn to knock code?
- PHP array splicing MySQL in statement
- [queue] 933 Number of Recent Calls
- One of the basics - overview of sta Basics
- [simulation] 922 Sort Array By Parity II
- 【队列】933. Number of Recent Calls
- System.CommandLine版CSRebot
- [fundamentals of wireless communication-14]: illustrated mobile communication technology and application development-2-the first generation mobile analog communication big brother
- 45岁程序员告诉你:程序员为什么要跳槽,太真实...
- 用 Flutter 的 Canvas 画点有趣的图形
猜你喜欢

KS009基于SSH实现宠物管理系统

Basic knowledge 3 - standard unit library

45岁程序员告诉你:程序员为什么要跳槽,太真实...

未来的 Web3会带来什么?

图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途

远程办公如何保持高效协同,实现项目稳定增长 |社区征文

For the sustainable development of software testing, we must learn to knock code?

Creating ASCII art with C #

Connectivity basis of Graphs

工作八年的程序员,却拿着毕业三年的工资,再不开窍就真晚了...
随机推荐
PHP数组拼接MySQL的in语句
短信在企业中的应用有哪些?
[queue] 933 Number of Recent Calls
Selenium经典面试题-多窗口切换解决方案
1500w播放下还藏着什么热点?B站2个未来趋势你不得错过
Open3d point cloud bounding box
微生物安全與健康,什麼是生物處理?
Relationship between ASCII, Unicode, GBK, UTF-8
医疗HIS行业短信发送解决方案
[Qt5 basics] random number display
Matlab farthest point sampling (FPS improved version)
Basic knowledge 3 - standard unit library
【多源bfs】934. Shortest Bridge
KS009基于SSH实现宠物管理系统
Creating ASCII art with C #
Working for eight years as a programmer, but with a salary of three years after graduation, it's too late to be enlightened again
Composants de la grille de données portatifs
Microbiological health, why is food microbiological testing important
Handsontable数据网格组件
System settings large page