Prototype equivalent for jQuery live function

前端 未结 2 1350
遥遥无期
遥遥无期 2020-12-01 04:01

I need to bind event listener to all dynamicaly created elements by given css selector.

In jQuery, that would be

$(\".foo\").live(\"click\", function         


        
2条回答
  •  渐次进展
    2020-12-01 04:22

    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()
      }
    });
    

提交回复
热议问题