I have some html.
<a href="#">
<i class="some-bg" />
Some Text
</a>
And some Javascript.
$("a").bind("touchstart", function (e) {
e.preventDefault();
console.log("Tag: " + e.target);
console.log("Tag Name: " + e.target.tagName);
});
The response is.
Tag: [object HTMLElement]
Tag Name: I
Why? Shouldn't it be anchor?
UPDATED
$("a, a *").bind(function() {
e.stopPropagation();
// other stuff
});
Will this do the trick?
Why?
Because you touched the <i>
(and then the event bubbled up to the <a>
).
Shouldn't it be anchor?
No. Use currentTarget
if you want the element to which the event is bound rather then the one which actually triggered the event.
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