JSFiddle - React, Tailwind, and code Playground

by Salmin Skenderovic

HTML

<div data-bind="text: name, myBinding: name()=='salmin'"></div>
 
 <button data-bind="click: toggleName">toggle</button>

JavaScript

ko.bindingHandlers.myBinding = {
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
        // This will be called when the binding is first applied to an element
        // Set up any initial state, event handlers, etc. here
    },
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
        
        var val = ko.unwrap(valueAccessor());
        
        element.setAttribute("test", val);
        
        // This will be called once when the binding is first applied to an element,
        // and again whenever any observables/computeds that are accessed change
        // Update the DOM element based on the supplied values here.
    }
};



function vm() {
this.name = ko.observable("salmin");

  this.toggleName = function(){
		var namnet = this.name();
    if (namnet == "skenderovic") {
    		this.name("salmin");
    } else {
    		this.name("skenderovic");
    }
  }
}

var vm = new vm();

ko.applyBindings(vm);