更改另一个div点击的特定类背景颜色



我想更改另一个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";
});

相关内容

  • 没有找到相关文章

最新更新