JSFiddle - React, Tailwind, and code Playground
HTML
<a data-bind="confirmClick: { message: 'Are you sure?', click: someMethod }">Confirmable link</a>
JavaScript
ko.bindingHandlers.confirmClick = {
init: function(element, valueAccessor, allBindings, viewModel) {
var value = valueAccessor();
var message = ko.unwrap(value.message);
var click = value.click;
ko.applyBindingsToNode(element, { click: function () {
if (confirm(message))
return click.apply(this, Array.prototype.slice.apply(arguments));
}}, allBindings);
}
}
ko.applyBindings({
someMethod: function(vm) {
alert('Some method executed')
}
})