Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 252
celsowm Avatar asked Jan 27 '11 17:01

celsowm


1 Answers

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.

like image 77
wajiw Avatar answered Sep 22 '22 15:09

wajiw