Hi Steph
Perhaps html label and input[type=radio] elements, with the checked binding, are a good choice for a list of items that are toggled. The jsFiddle shows some CSS to make the radio inputs look a bit less like the standard browser rendering, if required. Then a simple jQuery behavior to add the additional css classes, may be a pragmatic approach, rather than using the css binding.
Andy
<label><input type="radio" name="choice" value="1" data-bind='checked: choice'/> Option 1</label>
<label><input type="radio" name="choice" value="2" data-bind='checked: choice'/> Option 2</label>
<label><input type="radio" name="choice" value="3" data-bind='checked: choice'/> Option 3</label>
<p>Selected option: <span data-bind='text: choice'></span></p>
$('input[type=radio]').change(function() {
var label = $(this).closest('label');
var name = $(this).attr('name');
$(document.getElementsByName(name))
.closest('label')
.removeClass('selected');
label.addClass('selected');
});
var viewModel = {
choice: ko.observable(3)
};
ko.applyBindings(viewModel);
$('input:checked').trigger('change');
label {
display: block;
border: 1px solid #ececec;
padding: 0.2em;
margin: 0.2em;
}
input[type=radio] {
display: none;
}
.selected {
font-weight: bold;
background-color: #ececec;
}