- DOM. / . , . , , .
, , jQuery $.fn.live, , .
document.observe('click',function(event){alert(event.element().inspect())})
You can use this to make the jQuery live clown pretty easy (I'm not saying this will work well or something else).
live = function(selector,callback){
document.observe("click",function(e){
var element = e.element()
if (!element.match(selector))
element = element.ancestors().find(function(elem){return elem.match(selector)});
else
element = null
if (element)
callback.apply(element)
})
}
You can call it like this:
live("div",function(){this.setStyle({color:'blue'})})
I assume that I say that event delegation is already built into javascript. Libraries just add sugar.
source
share