I have the following:
<ul id ='foo'>
<li><p>hello</p></li>
<li><p>hello</p></li>
<li><p>hello</p></li>
</ul>
$('#foo').delegate('li', 'click', function(event) {
var target = $(event.target);
console.log(target);
});
the click handler gets called whenever one of the inner p elements gets clicked, as well as the parent li elements.
How can I get a pointer to the parent li element, regardless of which inner child element was clicked? For example, my real li elements look like:
<li>
<p>one</p>
<div>
<p>two</p>
</div>
</li>
so I'm finding I have to have several checks to get back up to the parent li that was clicked. Is there a way to just select the parent of a type like:
$('#foo').delegate('li', 'click', function(event) {
var target = $(event.target).('li');
console.log(target); // will always be parent li element itself?
});
Thanks
In the handler, this
will refer to the li
element.
$('#foo').delegate('li', 'click', function(event) {
var target = $(this);
console.log(target); // will always be parent li element itself?
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With