I am able to successfully disable a button with below syntax .
$("#list *").attr("disabled", "disabled").off('click');
However I also need to enable the button at the end of my function.Any pls help me here how to do this.
Don't use the attribute to disable the field. Use the property of the DOM element. To disable:
$("#list *").prop("disabled", true);
To re-enable:
$("#list *").prop("disabled", false);
The
.off()method removes event handlers that were attached with.on()
If you remove the event handler while you are disabling the button, even if you enable it later, it doesn't have the event handler anymore so clicking it won't trigger whatever functionality it had previously. Else you'll have to rebind the event handler as well after enabling it.
Simply disabling the button will prevent it from working, You don't have to remove the click handler at all.
You can disable the button using $("#list *").prop("disabled", true); and enable it using $("#list *").prop("disabled", false); as wolfgang Stengel mentioned in his answer
Try removing the disable property completely.
$('#list').removeAttr('disabled');
Update
One more thing, setting disabled to true,false,undefined etc doesn't do anything. You can check this by simply adding a disable attribute to an element(without passing it anything) and will keep it disabled forever
Update 2
As mentioned above, following fiddle describes the affects of passing 'true,false,undefined` in the disable attribute.
disabled to true and false. BTW attr is not the preferred way to alter property values...
.off("click")so just theattr("disabled", "disabled")is there. To re-enable doremoveAttr("disabled"). That's a horrible selector btw, do something like$("#list button")$(..).prop('disabled', false)