add disabled to button javascript code example

Example 1: jquery disable input

//jQuery 1.6+ use:
$("#inputID").prop('disabled', true); //disable 
$("#inputID").prop('disabled', false); //enable

//jQuery 1.5 and below use:
$("#inputID").attr('disabled','disabled'); //disable 
$("#inputID").removeAttr('disabled'); //enable

Example 2: javascript disable button

//disable the button
document.getElementById(BUTTON_ID).disabled = true;
//reable the button
document.getElementById(BUTTON_ID).removeAttribute('disabled');

Example 3: remove disabled attribute javascript

document.getElementById('my-input-id').disabled = false;

Example 4: javascript how to disable a button

//Using Javascript
//Disabling a html button

document.getElementById("Button").disabled = true;
//Enabling a html button

document.getElementById("Button").disabled = false;


//Using jQuery
//Disabling a html button

$('#Button').attr('disabled','disabled');
//Enabling a html button

$('#Button').removeAttr('disabled');

Example 5: javascript disable button

document.getElementById(BUTTON_ID).disabled = true;

Tags:

Html Example