Custom Events
May 7th, 2009
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.
Inline bind 1:
Inline bind 2:
Here is the code, or you can download it here:
- $(’select.test’).change( function() { $(’select.test’).trigger(‘update’, $(this)); } );
- $(’select.test’).bind(‘update’, function(e, data) { $(‘.test1′).html(data) });
- $(’select.test’).bind(‘update’, function(e, data) { $(‘.test2′).html(data) });
- var object1 = new function() {
- var obj = this;
- this.name = “Object 1″;
- $(’select.test’).bind(‘update’, function(e, data) { obj.update(data); });
- this.update = function(data){
- console.log(“Update from %o with %o”, this, data);
- };
- return this;
- };
- var object2 = new function() {
- var obj = this;
- this.name = “Object 2″;
- $(’select.test’).bind(‘update’, function(e, data) { obj.update(data); });
- this.update = function(data){
- console.log(“Update from %o with %o”, this, data);
- };
- return this;
- };