useranon
useranon

Reputation: 29514

Unbind not working in jQuery

I have a button and wrote two functions for the same button

Like initially

  $("#FieldSetting .button").eq(0).unbind('click');
  $('.button').eq(0).click(function(){alert('initally');})

later in the jQuery when I click on a div I wrote another function to be implemented by the same button as

 $("#fb_contentarea_col1down21 div").live("click", function(){
       $("#FieldSetting .button").eq(0).unbind('click');
       $('.button').eq(0).click(function(){alert("later");})
 });

In both the cases I have unbound the events but it didn't work.

My first function for the button works initally but afer I make use of the second function, my first function no longer works; the second function didn't ever unbind.

Please suggest how to resolve it.

Upvotes: 0

Views: 5308

Answers (1)

Sampson
Sampson

Reputation: 268462

If you run "unbind" at line 1, and then you attach a new event at line 10, the most recent activity will take authority. Meaning, whatever you did last, is King.

In this case, you added the .click() functionality long after you ran "unbind." Unbind isn't like live, it won't prevent you from ever tying a new set of functionality to a item - it will only unbind anything that has been tied to it up to that point.

Upvotes: 6

Related Questions