Skip to content

Bindings contenteditable

scottmessinger edited this page Sep 13, 2011 · 1 revision

Code

ko.bindingHandlers.contenteditable = {
    init: function(element, valueAccessor, allBindingsAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor());
        $(element).html(value)
    },

    update: function(element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor());
        if ((value === null) || (value === undefined)) {
            value = "";
        }
    }
};
Clone this wiki locally