Consider the following HTML:
<a href="#" id="aElement" data-bind="click: printId">
<span id="spanElement">Click Me</span>
</a>
When I click on the link, I have a printId function that is called:
printId: function (item, event) {
vm.textTest(event.target.id);
}
I would expect that the event.target.id value to be aElement, since that is the element that I have my click binding set to, but instead it is spanElement. Is there a reason why this is the case?
I'm guessing it is because that the actual "substance" that I am clicking on is the span element, but I still think it would make better sense to grab the anchor element instead from a coding standpoint. After all, I may have multiple elements inside that anchor tag and I may want to consistently get a single id every time rather than whatever id might be thrown my way based on where the user clicks inside the anchor tag.
However, this may be a JavaScript issue rather than a knockout issue. Any thoughts?
Here is a fiddle: