当前位置:网站首页>[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;
}
边栏推荐
猜你喜欢

New opportunities for vr/ar brought by metauniverse

物业怎么发短信通知给业主?

The personal test is effective, and the JMeter desktop shortcut is quickly created

Qt5 mvc: revealing the secrets of data visualization

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

测试必备工具-Postman实战教程

Gin configuration file

Connectivity basis of Graphs

Use of typora

日志 logrus第三方库的使用
随机推荐
Creating ASCII art with C #
45 year old programmer tells you: why do programmers want to change jobs? It's too true
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
mysql插入\更新前+判断条件
【动态规划】路径dp:931. Minimum Falling Path Sum
工作八年的程序员,却拿着毕业三年的工资,再不开窍就真晚了...
数据探索电商平台用户行为流失分析
Visual studio 2019 Download
TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
[Qt5 tab] tab label and content hierarchical analysis
小程序中实现excel数据的批量导入
Some essential differences
物业怎么发短信通知给业主?
One of the basics - overview of sta Basics
"Open math input panel" in MathType editing in win11 is gray and cannot be edited
PHP通过第三方插件爬取数据
1175. Prime Arrangements
Open3d point cloud color rendering
Neo4j installation, operation, project construction and function realization