removeClass does not work

Asked

Viewed 134 times

0

I need to validate two fields in my form to enable the Submit button for the final user, however the removeClass('disabled') not working.

    $('#main-form').on(function () {
        simCode = $('#main-form [name=code]').val().length;
        carrierId = $('#main-form [name=carrierId]').val();

        if (simCode == 20 || carrierId != "null") {
           $('#save').removeClass('disabled');
        }
    });

Remembering that simCode receives the values of an input type text and carrierId receives the value of a select option

2 answers

2


The disabled it’s not a class, it’s a property.

Use:

$('#save').prop('disabled', true);

Example:

function desabilita(){
  $('#save').prop('disabled', true);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0)" onclick="desabilita()">Clique aqui para desabilitar o botão abaixo</a>
<br>
<button type="button" id="save">Botão</button>

1

You did not include your html, but to what all indicates the disabled referred is not a style class but an attribute of the element.

$('#main-form').on(function () {
    simCode = $('#main-form [name=code]').val().length;
    carrierId = $('#main-form [name=carrierId]').val();

    if (simCode == 20 || carrierId != "null") {
       $('#save').attr('disabled', false);
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.