Skip to content
Advertisement

How to select a distant parent from a child (button element) nested deep inside a div?

I’m trying to select the form element which is the distant parent of a button. The button is deeply nested inside of a div. I have two type of forms in two pages so I’m using the same event for both of them. That’s why I’m using bother the selectors separated by a comma.

JavaScript
JavaScript
JavaScript

What I tried so far:

JavaScript

Please note that the same jQuery code works when I use an input element instead of a button. Although the input element is one level out of a div than the button.

Advertisement

Answer

This is the correct working code

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement