http://stackoverflow.com/questions/11903293/toggle-disabled-attribute-in-jquery/11903335#11903390

Benchmark created by Lorenzo C on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
first method

                        $("#filtri").change(function(){
                                if ($("#menuContinenti").attr("disabled")) {
                                        $("#menuContinenti").removeAttr("disabled");
                                } else {
                                        $("#menuContinenti").attr("disabled", "disabled");
                                }
                        });
ready
secondm ethod
$("#menuContinenti").prop('disabled', function (_, val) { return ! val; });
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Lorenzo C on