Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  9] [ 4]  / answers: 1 / hits: 74242  / 12 Years ago, tue, may 22, 2012, 12:00:00

I need to have multiple data bindings on one element. For example, I want a href as well as a html data-binding on one a tag. I have tried this,



<a data-bind=html: name 
data-bind=attr: { href: url }
data-bind=attr: { 'data-prop': xyz }>
</a>


But this doesn't work. It seems knockout only supports binding one data-bind property? How to bind both the href, the inner html, and a custom data-prop attribute on one element?


More From » jquery

 Answers
9

Like this:





<a data-bind=html: name, attr: { href: url }>


You use comma-separated bindings - the attribute is the same as passing an object:



{
html: name,
attr: { href: url }
}


Or, if you're asking about multiple attr bindings at once:



<a data-bind=html: name, attr: { href: url, 'data-prop': FullName }>

[#85426] Monday, May 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rocioblancac

Total Points: 699
Total Questions: 96
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;