+1 vote
by
Hi all!!!! There is this HTML construction:
<div class='block'>
<div class='block__inner'>
<button class='btn'></button>
</div>
</div>
When I click on a button with the class btn, I need to check the actions of the div with the class block. How do I do this in javaScript? But there are a lot of such blocks, it is the parent block that needs to be changed.
by
My profile, what I want and what I write, it should not concern you.


Sergey Zenkovich You're right there, but as they say "the fence is written on the fence" and you are in the role of the fence)
by
0xD34F My profile, what I want and what I write, it should not concern you.
by
Could you please stop misinforming people? Your profile now says "Front-end developer" in the "summary about yourself" section. Which, given the question at hand, is patently untrue. Fix it to "shitcoder," for example.

2 Answers

0 votes
by
 
Best answer
.addEventListener("click", (e) => {
console.log(e.target.parentNode)
console.log(e.target.parentNode.parentNode)
});
0 votes
by
Learn to google such elementary questions.

Your task can be broken down into three parts:
1. Installing handler click
2. Finding parent item
3. Performing the necessary actions with the parent

For all three items, information can easily be found through a search.
...