0

If one Jquery plugin this code is executed:

dropdown = {
    doc: $(document),
    element: $('#user_info'),
    open: function() {
        if ( ! dropdown.element.hasClass('active') ) {
            dropdown.element.addClass('active');
            dropdown.doc.one( 'click', dropdown.close );
            return false;
        }
    },
    close: function() {
        dropdown.element.removeClass('active');
    }
};

dropdown.element.click( dropdown.open );

How can I disable/remove/unbind the click handler in my own custom (another file) Jquery plugin?

I was using this code:

dropdown = {
    doc: jQuery(document),
    element: jQuery('#user_info')
};

dropdown.element.click(function(e) {
    dropdown.element.unbind('click', dropdown.open);
});

I get what I want, but javascript console shows this error:

TypeError: Object #<Object> has no method 'unbind'...

Please let me know if there is a way to avoid this error.

Thanks in advance.

2 Answers 2

1

Please let me know if there is a way to avoid this error.

From you example it looks like you're missing a property name in your call to unbind. Don't you mean this?

dropdown = {
    doc: jQuery(document),
    element: jQuery('#user_info')
};

dropdown.element.click(function(e) {
    dropdown.element.unbind('click', dropdown.open);
});

Notice dropdown.element.unbind(). The variable dropdown isn't a jQuery object from your example, but dropwdown.element is.

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

2 Comments

Thanks Zack, I try it, but it doesnt work. But it works like a charm with the answer that I just post a few minutes ago.
Do you mean it doesn't do what you want or it still generates an error?
0

Ok, I get it:

dropdown = {
    doc: jQuery(document),
    element: jQuery('#user_info'),
    open: function() {
        dropdown.element.addClass('active');
        dropdown.doc.one( 'click', dropdown.close );
        return true;
    },
    close: function() {
        dropdown.element.removeClass('active');
    }
};

dropdown.element.click( dropdown.open );

Comments

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.