0

I've got this simple button made using jquery UI with a very simple click functionality:

    $('#bewerkopslaan').button({
        icons: {
            primary: 'ui-icon-disk'
        },
        disabled: true
    }).click(function() {
        alert('test');
            });

At some point I enable the button like this:

    $('#bewerkopslaan').button("option", "disabled", false);

Then I can click the button but... nothing happens. Then I click it again and it works. So I always have to click it twice.

3
  • 1
    Are you enabling the button in a click handler on the button? Mind posting a jsfiddle.net or jsbin.com demo? Commented Mar 11, 2011 at 16:32
  • which navigator are you using? Commented Mar 11, 2011 at 16:35
  • I'm using chromium. Strange enough, the code works great in Firefox. (albeit a little slower ;)) Commented Mar 11, 2011 at 17:10

2 Answers 2

2

I wrote exactly what you mentioned but, the code works great. Look here.

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

Comments

1

The code you provided will enable the button correctly from my testing, however, the button having a disabled state does not disable the click event you've added. If you want the button to be truly disabled you need to bind the event only when you enable the button and unbind the click when you disable the button.

example can be found here: http://jsfiddle.net/WmAQJ/1/

<html>
<head>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.5.js'></script>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js"></script>

  <script type='text/javascript'>
  $('#bewerkopslaan').button({
    icons: {
        primary: 'ui-icon-disk'
    },
    disabled: true
  });

  $('#enabler').click(function() {
      $('#bewerkopslaan').button("option", "disabled", false).bind("click", function() {
        alert('test');
      })
  });

  $('#disabler').click(function() {
      $('#bewerkopslaan').button("option", "disabled", true).unbind("click")
  });
  </script>
  <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/base/jquery-ui.css" type="text/css" media="all" /> 
  <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" /> 
</head>
<body>
  <div id="enabler">click me to enable button</div>
  <span id="bewerkopslaan">button</span>
  <div id="disabler">click me to disable button</div>  
</body>
</html>

2 Comments

The click event wasn't triggered when the button was disabled. However, I still implemented your method. It works in Firefox, but not in Chromium.
What version are you running? This works fine for me in Chrome 10.0.648.133 Have you customized your Chromium at all before building it?

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.