I have such a piece of html:
<li class="addToFriends"><a href="....">Something something<span>INSIDE SPAN</span>something</a></li>
To handle AJAX request when clicking on anchor I have registered handler on click event:
$('.addToFriends a').click(function(event){
var target = $(event.target);
if (target.is('a')) {
// if I click on SPAN element following fragment won't execute!
// do ajax request
}
event.preventDefault();
});
My questions are:
So now, I got round that problem I my solution is:
$('.addToFriends a').click(function(event){
var target = $(event.target);
if (!target.is('a')) {
target = target.parent('a')
}
...
});
But still, I'm curious why it works like this...
Thanks,
Paweł
You have to use the currentTarget of your event.
$('.addToFriends a').click(function(event){
event.currentTarget;
...
});
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