style the textContent of parentElement

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

(https://i.stack.imgur.com/xnXeB.png)

我是 js 新手,在使用 nextElementSibling 属性更改按钮的 textContent 颜色时遇到问题

认为 e.target.childNodes.nextElementSibling.textContent.style.color = 'white' 会工作但没有(

javascript node.js
1个回答
0
投票

您将

style
属性与 DOM 元素一起使用,而不是与
textContent
属性一起使用!从您的代码中删除
textContent
以使其工作:

e.target.childNodes.nextElementSibling.style.color = "white";
© www.soinside.com 2019 - 2024. All rights reserved.