I have a HTML markup that looks like
<ul>
...
<li>
<ul class="x">
...
<a href="#"...
How can I get the parent ul.x element from a click event hooked on the link?
this.parentNode works if the UL is the parent element, but if it’s one of the ancestors I have to use this.parentNode.parentNode depending on how many parent elements are in between…
Can I somehow get the first UL parent?
For performance,
You can also use jquery on like below, jquery eventObject also has a property named delegateTarget, which could be useful in your case.
HTML:
In terms of performance, you are not binding the event on all the
atags. jQuery suggests this way.Here is the fiddle.