Post your trick

Custom Events in jquery

we can fire custom events in jquery and set an event handler for each event .

This enables loose coupling and code reuse . This can be used to achieve the observer design pattern .

$(’#txtAddress’).keyup(function() {

$(document).trigger(’ADDRESS_CHANGE’);

});

$(’#txtCity’).keyup(function() {

$(document).trigger(’CITY_CHANGE’);

});

to now bind the event :

$(document).bind(’ADDRESS_CHANGE’, function(e) {
UpdateName();
UpdateOtherText(e);
});

Hack Away ;)


Leave a Reply

     

     

     

Post A Trick !

How does "Kodetricks" work?

We at kodeplay like to share knowledge. With Kodetricks, even you can join us. All you need to do is post a programming related trick if you have one or rate a trick if you like someone else's.



Technology

Contact Us