I'm trying to bind anchor attributes to a KnockoutJS ViewModel field. I tried something like this:
<a data-bind="href: Link, value: Title"></a>
but this doesn't work. Where I can get a list of possible data-bind values for html elements?
The anchor tag has a required attribute, href (short for “Hyperlink Reference”), and the value of this attribute is a URL which represents the destination for the browser when the link is clicked. The anchor tag also supports a special option attribute, target.
The HREF is an attribute of the anchor tag, which is also used to identify sections within a document. The HREF contains two components: the URL, which is the actual link, and the clickable text that appears on the page, called the "anchor text."
A data binding connects data from a custom element (the host element) to a property or attribute of an element in its local DOM (the child or target element). The host element data can be a property or sub-property represented by a data path, or data generated based on one or more paths.
Using data-href So, if you click an element with a data-href, you go to the data-href URL; if you click a link inside of that element, you go to the URL on that link.
You need to use the attr
binding, this allows you to set any attribute you like.
For example:
<a data-bind="attr: { href: Link, title: Title }, text: Title">xxx</a>
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