I want to add class in ko template

In js:

    ], function ($, ko, Component, _, $t, storage, urlBuilder, customer, quote, checkoutData) {
        'use strict';
        return Component.extend({
            errorMessage: ko.observable(false),
            showElement: ko.observable(),

            initialize: function () {
                this.showElement = this.resolveInitialVisibility();
                return this;

            resolveInitialVisibility: function () {
                if (checkoutData.getInputFieldEmailValue() !== '') {
                    return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();

                return false;

I need to add disable class for <div class="col-md-12 pdl0"> if the showElement returns true.

How to do that



You can use like this:

<div class="col-md-12 pdl0" data-bind="css: {'disable': showElement} ">

or like this:

<div class="col-md-12 pdl0" data-bind="css: showElement ? 'disable' : ''">
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.