I know I can do this with Javascript:
var els = document.querySelectorAll('a.foo');
for (var i = 0; i < els.length; i++) {
els[i].addEventListener("click", function() {
// the callback
});
}
In jQuery I could do:
$(document).on("click", "a.foo", function() { alert("foo") });
The first example I gave requires me to re-do this on EVERY new item I add - whereas the jQuery one will trigger even on new elements.
How does jQuery get around this?