There is prototype js function:
Event.observe(element, eventName, handler)
here the element means element's ID.
Is it possible to put here element's class?
I got this element from third party with class attribute only.
$$ can retrieve elements by css selector, including by class via the period notation .:
$$('.myClass'); // array with all elements that have class "myClass"
To answer your question, Event.observe is the "static" version of observe (for all intents and purposes). As a convenience Prototype automagically makes .observe available off of all DOM elements (fetched with either $ or $$):
Examples:
// get one item by id with $ and attach an event listener:
$('myId').observe(eventName, handler);
// get many items by class with $$ and attach an event listener:
$$('.myClass').each(function(element) {
  element.observe(eventName, handler);
});
// or shorter:
$$('.myClass').invoke('observe', eventName, handler);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With