[edit:not()javascript选择器

问题描述 投票:1回答:2

我在CSS中为.square类使用此选择器

.square:not(:hover){
}

并且我想通过javascript向其添加自定义属性

我尝试做这个愚蠢的事情,当然它没有用

document.querySelectorAll('.square:not(:hover)').forEach((item) => {
  item.style.transition = `background ${animation_delay}s`;
});

有什么办法可以使用香草js吗?

javascript html css dom css-selectors
2个回答
0
投票

访问/修改<style>标签的方法如下:


0
投票

document.querySelectorAll('.square:not(:hover)')应返回节点列表。语法没错。

© www.soinside.com 2019 - 2024. All rights reserved.