-
Notifications
You must be signed in to change notification settings - Fork 1.5k
API Reference: Bindings
Back to API Reference
attr
checked
click
css
disable
enable
event
foreach
hasfocus
html
if
ifnot
options
selectedOptions
style
submit
template
text
uniqueName
value
visible
with
Set the value of any attribute of the DOM node.
A JavaScript object in which the property names correspond to attribute names, and the values correspond to the attribute values. If an observable is referenced, the value will be updated accordingly (a one-way binding though—see checked or value for two-way bindings).
<a data-bind="attr: {'href': url, 'title': linkTitle}">link text</a>
Tie the state of a checkbox or radio button form control to a view model.
- checkbox state tied to an observable
- Pattern: control a boolean
- Initially, the javascript thruthiness of the observable determines the checked state of the checkbox.
- Checking it will set the observable to true.
- Unchecking it will set the observable to false.
- checkbox state tied to an observableArray
- Pattern: control the inclusion of an element in a set
- Initially, if the checkbox's value attribute is found in the array, it will be checked.
- Checking it will add the value to the array.
- Unchecking it will remove the value from the array.
- radio state tied to an observable
- Pattern: select the value of an enum (each radio representing one possible value)
- Initially, if the radio's value attribute matches the observable's value, it will be checked.
- Checking it will set the observable to the radio's value attribute.
Binding order affects checked. In most cases, if using the value binding together with the checked binding, you will want to specify the value binding first. E.g. data-bind="value: val, checked: checkedValue" (for both checkbox and radio buttons).