[英]How can I change textContent in DOM if object is declared and assigned
right now this line of code shows whats in DOM现在这行代码显示了 DOM 中的内容
let scoreDisplay = document.querySelector('.score').textContent
but if i want to change the textContent it doesnt work, why?但是如果我想更改 textContent 它不起作用,为什么?
scoreDisplay = "twenty five"
the change is visible only in console.log but not in DOM, how can i make it affect the DOM as well?更改仅在 console.log 中可见,但在 DOM 中不可见,我怎样才能使其也影响 DOM?
You are changing the value of the variable, not of the element itself.您正在更改变量的值,而不是元素本身的值。 Try modifying your code to尝试将您的代码修改为
let scoreDisplay = document.querySelector('.score')
scoreDisplay.textContent = "twenty five"
or even as a one-liner:甚至作为单行:
document.querySelector('.score').textContent= "twenty five"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.