Question

Given the following code:

    if ($selector.html().indexOf("radio") > 0) {

        if ($oldSelected != null) {
            // enable clicks on old selected radio button
            $oldSelected.children().bind('click', function () { return true; });
        }

        // disable click on selected 
        $selector.children().bind('click', function () { return false; });
        $oldSelected = $selector;
    }

The disabling code works fine. Once executed the element is no longer clickable. However, when trying to re-enable the click event, nothing happens.

Suggestions?

Était-ce utile?

La solution

You're just binding click handlers over and over again. You need to unbind() the ones you don't want active.

Try this:

$oldSelected.children().unbind('click').bind('click', function () { return true; });

On second thought, unbind('click') may be all you need if there's no other logic in your click handlers.

Autres conseils

Try something like:

var handler = function () {
    // do some stuff
};

// First
el.bind('click', handler);

// Later on...
el.unbind('click', handler);

Remember to save the callback so that later on you can unbind. Unbind docs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top