How to disable button using jquery in materialize css

Viewed 6091

I am using jquery to disable a button in materialize css. According to documentation here, the way to disable button is simply by adding a class named 'disabled'.I think by simply add class 'disabled', the button will automatically disabled, but it is not. Here is my code:

html:

<button id='submit-btn' class="btn waves-effect waves-light submit red" type="button" name="action">

jquery:

$('#submit-btn').off().on('click', function(){
    $('#submit-btn').addClass('disabled');
});
5 Answers

To disable the button using javascript.

eleme.classList.add('disabled');

To enable the button using javascript.

elem.classList.remove('disabled');

E.g:

let btn = document.getElementById('submit-btn');
btn.classList.add('disabled'); //This will disable the button

Create a variable which holds the button (say submitBtn), then add an event listener (say on DOMContentLoaded), then have the function disable the button with submitBtn.disabled = true;

Related