Internal Functionality Events

Internal Functionality Events


I was thinking it would be a good idea if you could bind events to the internal jQuery functionality. So I'm planning on making a plugin out of this idea. So I would like your opinions on this if there is anyone that tried this before. Any comments about potential benefits, pitfalls, possible additions... are welcome.

This is an example of how a binding would work:
  1. function test() {
  2.       //must not change content using append
  3.       //potential disaster
  4.       //$(this).append('something') would make an infinite loop
  5.    
  6.       //but this on the other hand
  7.       console.log('Test executed!');
  8. }


  9. var fn = jQuery.prototype.append;
  10. jQuery.prototype.append = function() {
  11.       fn.apply( this, arguments );
  12.       this.trigger('contentChanged.jQInternals');
  13. };


  14. $('body').bind('contentChanged.jQInternals', test);
  15. $('body').append('FOO!');
jsFiddle link