Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-bind href attribute for anchor tag

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?

like image 951
xwrs Avatar asked Nov 14 '11 14:11

xwrs


People also ask

Do anchor tags require the href attribute?

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.

What is href in anchor tag?

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."

What is data bind attribute in HTML?

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.

What is href data?

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.


1 Answers

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> 
like image 181
Richard Friend Avatar answered Oct 05 '22 11:10

Richard Friend