0

I've tried everything!

$('#m-button').button('disabled')
$('#m-button').attr('disabled', 'disabled')
$('#m-button').prop('disabled', 'disabled')
$('#m-button').attr('disabled', 'true')
$('#m-button').prop('disabled', 'true')
$('#m-button').attr('enabled', 'false')

<button id="m-button" class="btn" type="button" >Add Note</button>

It stays enabled though. What's the proper way to disable a <button>?

0

3 Answers 3

9
$('#m-button').prop('disabled', true)

without quotes around true.

jsFiddle example

Per the jQuery docs on .prop():

Properties generally affect the dynamic state of a DOM element without changing the serialized HTML attribute. Examples include the value property of input elements, the disabled property of inputs and buttons, or the checked property of a checkbox. The .prop() method should be used to set disabled and checked instead of the .attr() method.

Sign up to request clarification or add additional context in comments.

Comments

1

Remove the quotes from around true and use prop(), like follows:

$('#m-button').prop('disabled', true);

Comments

0

you can try this:

$('#m-button').attr('disabled', 'disabled')

all you need is just to add disabled attribute to your button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.