tags:

views:

599

answers:

1

Hi,

I am having 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 unbinded the events but it didnt works..

My first function for the button works initally but afer i make use of the second function ,then my first function not working,the second function didnt ever unbinds ..

please suggest me to resolve it.

+4  A: 

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.

Jonathan Sampson