Observing Dynamically loaded Elements with jQuery and Prototype

Angelegt von andi Mon, 09 Aug 2010 20:18:00 GMT

Both jquery and Prototype make it easy to attach Observers to dynamically loaded dom elements.

In Prototype:

document.observe('click', function(e, el) {
  if (el = e.findElement('.foo')) {
    // bar
  }
});

while in jQuery live does the job:

$(".foo").live("click", function(e) {
   // bar
});