Custom Events

Change the value of the drop down to see the events fired. Inline bind 1 and 2 will show you how to update an html element via a triggered event. In order to see the Object updates, you will need to have firebug installed. It will log the output to firebugs console.

Here is the code, or you can download it here:

  1. $(’select.test’).change( function() { $(’select.test’).trigger(‘update’$(this))} );
  2. $(’select.test’).bind(‘update’function(e, data) { $(‘.test1′).html(data) });
  3. $(’select.test’).bind(‘update’function(e, data) { $(‘.test2′).html(data) });
  4. var object1 = new function() {
  5.     var obj = this;
  6.     this.name = “Object 1″;
  7.     $(’select.test’).bind(‘update’function(e, data) { obj.update(data)});
  8.     this.update = function(data){
  9.         console.log(“Update from %o with %o”this, data);
  10.     };
  11.     return this;
  12. };
  13. var object2 = new function() {
  14.     var obj = this;
  15.     this.name = “Object 2″;
  16.     $(’select.test’).bind(‘update’function(e, data) { obj.update(data)});
  17.     this.update = function(data){
  18.         console.log(“Update from %o with %o”this, data);
  19.     };
  20.     return this;
  21. };
Bookmark and Share
  1. No comments yet.
  1. No trackbacks yet.