See this question. Except that the answer returns the child element when a child element is clicked, i.e. in the case that you bind a div.
<div id="parent" data-bind="click: log">Parent Div<div id="child">Child</div></div>
<script>
var ViewModel = function() {
this.log = function(data, event) {
console.log("you clicked " + event.target.id);
}
};
ko.applyBindings(new ViewModel());
</script>
See this fiddle
I want to get the original element the click event was bound to. Any suggestions?
event.currentTarget
will give you the element to which the event is bound. Change your Console.log as below:
console.log("you clicked " + event.currentTarget.id);
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