Jquery to disable a HTML button not working

jquery

Solution

You should be using

prop('disabled',true)
prop('disabled',false)

if you are using jQuery 1.6+ then you should be using prop.

Read more about 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. The `.val()` method should be used for getting and setting value.

Problem

I am trying to get some jQuery to disable the confirm button on my form if the dropdown list is a certain value, but it doesnt seem to be working. I have read lots of posts on here and tried various different ways. Here is my code at the moment: ``` <script> $(document).ready(function () { // Handler for .ready() called. $('#MoveToCompanyId').attr("disabled", true); $('#DeleteAll').live("click", function () { if ($(this).attr("value") == "True") { $('#MoveToCompanyId').attr("disabled", true); } else { $('#MoveToCompanyId').attr("disabled", false); $('#confirm').attr("disabled", true); $('#MoveToCompanyId').change(function () { if ($("#MoveToCompanyId option:selected").text() != "---Select Company---") { $('#confirm').removeAttr("disabled"); alert($("#MoveToCompanyId option:selected").text()); } else { $('#confirm').attr("disabled", true); alert("I should be disabled!"); } }); } }); }); </script> ``` Can anyone see any problems with it? Just to clarify, i know it gets into the correct code blocks as my alerts are working. Its just the button disabling that is not working. Kind Regards, Gareth

Original source

Related problems