I need a implementation of http://www.prot开发者_JS百科otypejs.org/api/event/observe in Jquery? With "frequency" too?
I need to a ticket for cakephp.
Thanks, Celso.
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.
in addition to
$('#myElement').bind('click', function(){...});
also take a look at
$(document).on('click', '#myElement', function(){...}); # jquery >= 1.7
which binds a click
event to all present and even future elements - especially usefull if you want multiple objects to react on clicks or which are added dynamically. See http://api.jquery.com/on/ for a more detailed explanation.
精彩评论