You are close. I updated your fiddle here with a solution.
HTML
<table class="table table-bordered"> <tbody data-bind="foreach: frameworks"> <tr data-bind="css: {'selected':$root.selectedItem() == $data}"> <td> <button class=btn data-bind="click: $root.doStuff">A</button> </td> <td data-bind="text: $data"></td> </tr> </tbody> </table>
CSS
.selected { background-color:red; }
Javascript
var App = new function () { var self = this; self.frameworks = ko.observableArray(); self.selectedItem = ko.observable(null); self.doStuff = function (item) { self.selectedItem(item);
source share