observe field using prototype Rails 3

Does anyone knows how to do an observe field using Prototype in Rails 3. An example would be useful as I am very weak programming in Ajax.

Don Mapp wrote in post #956253:

Does anyone knows how to do an observe field using Prototype in Rails 3. An example would be useful as I am very weak programming in Ajax.

Prototype

jQuery


$(document).ready(function() {

$(‘#foo’).click(function() {

$(this).css("backgroundColor", "blue");

});

});

Sorry but this is not equivalent to observe

this is

$(document).ready(function() {

$(‘#foo’).live(“click”,function() {

$(this).css("backgroundColor", "blue");

});

});

and it can be shorter

$($(‘#foo’).live(“click”,function() {

$(this).css("backgroundColor", "blue");

}));

to explain my previous comment, if you do

$(document).ready(function() {

$(‘#foo’).click(function() {

$(this).css("backgroundColor", "blue");

});

});

and you change the node holding the “foo” element, since you attached the click event on document ready, the event will not work again after the change, so with the live event you make the browser keep looking for “foo” element like the observe event from prototype, so if you update somehow the “foo” element the click event will be reattached

Thanks GUys I will try that and get back to you sometime.