【问题标题】:Change z-index value of a particular class through Javascript通过 Javascript 更改特定类的 z-index 值
【发布时间】:2016-05-25 04:17:16
【问题描述】:

如何将 Z-index 值从 3 更改为 0,如下例所示。它在内联css中。我只需要更改特定类的 z-index 值。它应该是用 JS 编写的,但是完整的代码是用 ES6 编写的。

<div class="xyz" style="position:absolute;z-index:3;top:0;left:0;">

【问题讨论】:

标签: javascript css node.js


【解决方案1】:
document.querySelector(".xyz").style.zIndex = 0

这将更改类xyz 的第一个元素的z-index。如果您想为该类的所有元素更改它,请使用 document.querySelectorAll() 并循环遍历元素:

for (const element of document.querySelectorAll(".xyz")) {
  element.style.zIndex = 0
}

【讨论】:

    猜你喜欢
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多