Take action on parent elements via javaScript?
-
Hello everyone!!!! There is such HTML construction:
<div class='block'> <div class='block__inner'> <button class='btn'></button> </div> </div>
When I click on the button with the btn class, I need to turn the actions with the div with the block class. How do I do this in javaScript? But there are many such blocks, it is the parent block that needs to be changed.JavaScript Adalyn Wallace, May 11, 2020 -
.addEventListener("click", (e) => {
console.log(e.target.parentNode)
console.log(e.target.parentNode.parentNode)
});Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!