Some Text And some javascript. $("a").bind("touchsta...">

HTML tag binding with Italic tag

I have 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); }); 

Answer.

 Tag: [object HTMLElement] Tag Name: I 

Why? Shouldn't it be an anchor?

UPDATED

 $("a, a *").bind(function() { e.stopPropagation(); // other stuff }); 

Will this do the trick?

+6
source share
1 answer

Why?

Since you touched <i> (and then the event woke up to <a> ).

Shouldn't he be attached?

Not. Use currentTarget if you want the element to which the event is bound, and not the one that actually raised the event.

+4
source

Source: https://habr.com/ru/post/897160/


All Articles