Jquery - Multi-Unbind
For example
i start a functionsomeName('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!
Peteryou can use unbind
or die
jquery unbind
jquery 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();
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');
精彩评论