how to unbind event by jquery – Education Career Blog

  if (IsBestanswer == "True") 
      {
        $(bestAnswer).addClass('IsBestanswer');
        $(bestAnswer).unbind('click');
      }
 bestAnswer.live('click', function()
{

// some code....
});

actually i want to disable click property on bestanswer while IsBestanswer == “True”.
here i am using unbind() function. but it’s not working …

is there any methode for disable like adding some css property …actually i don’t know..

,

To unbind a live handler, call die. (I didn’t make that up)

However, if bestAnswer is a single element, there’s no point in using live instead of bind.
live is designed to be used with a selector that will match elements in the future.

Also, if you can write bestAnswer.live, you don’t need to write $(bestAnswer), since it’s already a jQuery object.
(As opposed to a DOM element, selector, or HTML string which you would need to call $ on)

,

You could just do it in your handler, no unbinding necessary:

$("selector for answers here").live('click', function()
{
    if (!$(this).hasClass("IsBestanswer")) {
        // do something, this isn't the best answer
    }
});

Leave a Comment