Prototype - click event by element class name

前端 未结 2 1713
傲寒
傲寒 2021-02-13 18:41

I am new to the prototype framework and am trying something really simple and failing. I am trying to respond to a click event on a button like so:

$$(\'.btn\')         


        
2条回答
  •  失恋的感觉
    2021-02-13 19:00

    Unlike jQuery, handing selectors with multiple results in Prototype works a little differently. You need to handle each selected result separately using .each().

    $$('.btn').each(function(element) {
        element.observe('click', respond);
    })
    

    This is one of the reasons I moved over to jQuery. The other reason: knowing jQuery is marketable and knowing Prototype is not.

提交回复
热议问题