Search code examples
jqueryajaxobserver-pattern

How implement a "observer" in Jquery without plugins?


I need a implementation of http://www.prototypejs.org/api/event/observe in Jquery? With "frequency" too?

I need to a ticket for cakephp.

Thanks, Celso.


Solution

  • Prototype observe is equivalent to jquery bind

    so something like this in prototype:

    $('myElement').observe('click', function(){...});
    

    would be equivalent to this in jquery:

    $('#myElement').bind('click', function(){...});
    

    The actual implementation in the library is different, but this will provide a similar result. Also, in jquery you won't have to attach a bind() function on the end of your handler as jquery binds the scope automatically.