i have 2 buttons like below:
<button id="btnPrevious" class="icon-backward" data-bind="click: $root.GoForWeek"></button>
<button class="icon-forward" data-bind="click: $root.GoForWeek"></button>
I want to pass value in my method to know which button is clicked. My method is below:
self.GoForWeek= function (data, event) {alert(event.target);
//want to get id of button to know which button is clicked
$.ajax({
//code here
})
};
Try the code below for function declaration:
Now, event.target will tell you which button was clicked. You can then use
to access the element in jquery.
You can also use the data variable in this case to access any data you have added to the control thought knockout’s ‘data’ attribute in data binding.