There is no href
binding in the core KnockoutJS library, which is the reason all examples showcase other features of the library to get the same effect.
<a data-bind="attr: { href: myUrl }">link with dynamic href</a>
ko.applyBindings({
myUrl: ko.observable("http://www.stackoverflow.com")
});
Since there is no native href
binding in KnockoutJS, you need to use a different feature to get dynamic links. The above example showcases the built-in attr
binding to get a dynamic link.
href
binding is not native to KnockoutJS, so to get dynamic links use a custom binding handler:
<a data-bind="href: myUrl">link with dynamic href</a>
ko.bindingHandlers['href'] = {
update: function(element, valueAccessor) {
element.href = ko.utils.unwrapObservable(valueAccessor());
}
};