Override or delete a ready-made handler

I need to change the site that uses the jQuery handler, I will not reuse the code and will not write it again, however I need to change the behavior of the original finished handler, the question is:

  • How to remove a ready-made handler (apply a new one)?
  • or how to override an existing ready-made handler (the original uses an anonymous function)?

Best wishes

+4
source share
1 answer

Ok, apparently, you cannot unlock the ready handler, to be precise, you cannot when ready () is used, but you can use bind ("ready", handler), but instead

$(document).ready(handler); 

using

 $(document).bind('ready', handler); 

then whenever you want to modify an existing event handler, use:

 $(document).unbind('ready', handler);//when there is reference to the handler 

or

 $(document).unbind('ready');//to remove all handlers for ready event 

as I recently found, you can add an event namespace :) only to delete ready-made events in this namespace (I looked at the jplayer code) as follows:

 var GD_EVENT_NAMESPACE = ".GrelaDesign"; $document.bind('ready' + GD_EVENT_NAMESPACE, function(){ alert('ready'); }); //later $document.unbind('ready' + GD_EVENT_NAMESPACE);//this will remove only specific events 

Best wishes

ps I searched extensively before asking here :) and shortly after I asked, I found the answer :-)

+3
source

All Articles