If you want a custom binding, here's how you could implement one:
ko.bindingHandlers.customBinding = {
update: function(element, valueAccessor, allBindings) {
// Retrieve the latest data bound to this element
var value = valueAccessor();
// Get the current value of the model property, even if it's not observable
var custom = ko.unwrap(value);
if (custom) {
var customEl = $(element).data('custom');
// Create the custom element if it doesn't exist yet
if (!customEl) {
customEl = $('<div />').addClass('custom').appendTo(element);
customEl.height($(element).height()); // Match the height of the element
$(element).data('custom', customEl);
}
customEl.show();
} else {
var customEl = $(element).data('custom');
if (customEl) {
customEl.hide();
}
}
// You can also trigger the if-binding within this custom binding
// ko.bindingHandlers.if.update(element, valueAccessor, allBindings);
}
};
To use this custom binding, follow this syntax:
<div data-bind="customBinding: [condition]"></div>