I need to bind event listener to all dynamicaly created elements by given css selector.
In jQuery, that would be
$(".foo").live("click", function(e) {
// bar
});
Is there any equivalent in Prototype for this?
I need to bind event listener to all dynamicaly created elements by given css selector.
In jQuery, that would be
$(".foo").live("click", function(e) {
// bar
});
Is there any equivalent in Prototype for this?
This is usually done with Event#findElement
:
document.observe('click', function(e, el) {
if (el = e.findElement('.foo')) {
// there's your `el`
// might want to stop event at this point - e.stop()
}
});
what about using el.hasClassName
instead of e.findElement
document.observe('click', function(e, el) {
if (el = el.hasClassName('.foo')) {
// there's your `el`
// might want to stop event at this point - e.stop()
}
});
Maybe more performant?!