我想更改另一个div的click
上的div的背景颜色。我试过这个
HTML
<div class="post-main-content">
<br /><hr />
<p>
<br />
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequuntur,
iusto quasi eum, delectus, soluta aliquam modi suscipit non fuga fugiat
nemo ullam eos? Eaque soluta esse, dolore voluptates vitae sunt
recusandae libero provident accusantium ex nemo quaerat quidem cumque
corrupti voluptatibus cum debitis assumenda sequi veniam corporis quam
<p>
</div>
JavaScript
const backChange = document.querySelector('post-main-content').addEventListener("click", function(e){
e.backChange.style.background = "black"
})
还是不行
在querySelector
中添加点
const backChange = document.querySelector('.post-main-content');
backChange.addEventListener("click", function(){
backChange.style.background = "black";
});