tags:

views:

29

answers:

2
  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..

+3  A: 

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)

SLaks
A: 

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
    }
});
T.J. Crowder
actually i want to disable click event on bestanswer object when IsBestanswer == "True"
Nishant
@Nishant: Right. The logic above skips the body of the `if` statement if the element has the "IsBestanswer" class, which seems to be what the code in your question is trying to do. I'll change the name of the jQuery variable above, which I quoted from your question, since it's a bit misleading...
T.J. Crowder