Data-bind href attribute for anchor tag

xwrs picture xwrs · Nov 14, 2011 · Viewed 55.3k times · Source

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?

Answer

Richard Friend picture Richard Friend · Nov 14, 2011

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>