Reputation: 753
I'm using jQuery.on()
, and have the following code:
$('.parent').on('click', '.link',function (event) {
console.log($(this)); // Logs '.link'
});
How can i access to the '.parent' element in which the click was triggered?
$(this)
returns the '.link' element
Upvotes: 2
Views: 346
Reputation: 74420
You can use closest():
$(this).closest('.parent');
Or use: $(event.delegateTarget)
which will take into account multiple nested .parent
elements.
If your element is an anchor tag, you have surely to prevent default behaviour.
Upvotes: 5