javascript - Why does the knockout binding pass the span element's id rather than the anchor element's id? -
consider following html:
<a href="#" id="aelement" data-bind="click: printid"> <span id="spanelement">click me</span> </a> when click on link, have printid function called:
printid: function (item, event) { vm.texttest(event.target.id); } i expect event.target.id value aelement, since element have click binding set to, instead spanelement. there reason why case?
i'm guessing because actual "substance" clicking on span element, still think make better sense grab anchor element instead coding standpoint. after all, may have multiple elements inside anchor tag , may want consistently single id every time rather whatever id might thrown way based on user clicks inside anchor tag.
however, may javascript issue rather knockout issue. thoughts?
here fiddle:
js fiddle demo
the click event span bubbles dom. use event.currenttarget refer element event handler has been attached to.
https://developer.mozilla.org/en-us/docs/web/api/event.currenttarget
Comments
Post a Comment