Reputation: 11835
what is the best way to unbind all?
For example
i start a function someName('mp3Player')
in this function are many binds
function someName(mode)
{
if(mode == 'exit')
{
$('#player').remove();
// unbind all
// ..........
return true;
}
if(mode == 'mp3Player')
{
$('body').append('<div id="player"> *** add some html code *** </div>');
$('#test').draggable ....
$('.myLi').sortable ....
$('myButton').click ....
$('.dragable').live( "dragstop", function (event, ui) ....
return true;
}
}
Any good ideas?
Thanks in advance!
Peter
Upvotes: 0
Views: 213
Reputation: 31043
you can use unbind
or die
in your case you are live
bundingthe event so its better/necessary to use
die` as
$('.dragable').die('dragstop');
to unbind single event as maxedison mentioned do
$("element").unbind("eventName");
this will unbind the event attached to the element to unbind all the events attached to an element call unbind without any arguments
$("selector").unbind();
Upvotes: 1
Reputation: 17573
The simplest way to do it would be to simply call something like the following on each element:
$('mySelector').unbind('eventName');
For example:
$('.myButton').unbind('click');
Upvotes: 1