0

How to use icons instead of buttons?

I have to regularly turn on and off the icons depending on user actions.

So I can easily change the image of the icon but how do I disable the click event.

I try to use "bind" and "unbind" but it causes me a lot of problems.

The accumulation of "bind" repeatedly invoke the same function.

I tried the method. One

Do you know a better way?

Thanks :)

1
  • Add a class (like "disabled")... and then inside the click handler check with hasClass(). Commented Jul 4, 2011 at 19:01

1 Answer 1

2

Disabling the element:

x.addClass('disabled');

Enabling the element:

x.removeClass('disabled');

The click handler:

x.click(function() {
    if ( $(this).hasClass('disabled') ) { return; }
    // continue normally
});
Sign up to request clarification or add additional context in comments.

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.