javascript - 如何使用 JS 在 HTML 中定位特定的 span 标签
问题描述
嗨,我有一个带有几个 HTML 的 HTML,并且只有几个我想要淡化的 span 标签。
我选择了所有跨度:
const spans = document.querySelectorAll("span");
const animation = function () {
for (let span of spans) span.classList.toggle("fade");
};
setInterval(animation, 2400);
现在我只想在 div 中定位这两个跨度
<div class="animated">
Hey, I'm<br>
<span
class="color-primary mt-5 fade"
id="animated-name"
style="margin-top: 20px;"
>
Name Name
</span>
<span
class="color-primary mt-5"
id="animated-text"
style="margin-top: 20px;"
>
Text Text
<br>
Text & Text
</span>
</div>
我的问题是如何仅针对这 2 个跨度标签来切换淡入淡出?
解决方案
为什么不使用document.querySelectorAll('div.animated > span')
?
推荐阅读
- python - 如何同时使用 Python 多处理和异步?
- powershell - 使用不同帐户登录返回错误页面
- linux - 使用 Qemu 用户模式运行 ARM64 二进制文件的问题
- ios - 信号量永远等待
- ios - 由于文件“不存在”,Swift MoveItem 失败
- javascript - 如何创建一个删除按钮,我可以在其中删除数据库一侧的列表?
- c# - 外键问题(将实体种子添加到“注释”并指定外键值 {“DocumentId”}。)EF
- python - 为什么使用 pyDICOM 和 matplotlib 可视化 DICOM 文件会返回绿色图像
- angularjs - 如何使用 Ionic v1 登录 Fantasy Premier League
- javascript - 组件状态中的属性更新速度不够快