jQuery ready - how to strip an existing ready handle?
I've been asked to perform maintenance on a third part开发者_开发知识库y site, I can edit the javascript but not the back end code. This site uses a plugin which sets various styles and events up in a jQuery.ready call. I want to stop it without causing errors. I can insert javascript before and after the plugin in the template but the markup inside the plugin comes from elsewhere. I have tried something like this:
<script>
var tmpReady = $.ready;
$.ready = function() {};
</script>
<pluginWhichICanNotChange>
$(document).ready( function(){ BAD STUFF } );
</pluginWhichICanNotChange>
<script>
$.ready = tmpReady;
</script>
But the BAD STUFF still fires. Anyone any idea how I can strip it!?
That's because the methods that work with selectors reside in the $.fn
namespace. The following should work:
<script>
var realReady = $.fn.ready;
$.fn.ready = function() {};
</script>
<pluginWhichICanNotChange>
$(document).ready(function() { /* BAD STUFF */ });
</pluginWhichICanNotChange>
<script>
$.fn.ready = realReady;
</script>
精彩评论