views:

201

answers:

2

hi , in jQuery. i am invoking an event by class. how do you do same in Prototype.

$(".button").click(function() {
  var element = $(this);
  var Id = element.attr("id");
});
+2  A: 
$$('.button').observe('click', respondToClick);

function respondToClick(event) {
   var element = event.element();
   var Id = element.id;
}

http://www.prototypejs.org/api/event

karim79
You've got some messed up quotation marks in there, and I think you mean $$(), not $().
Sixten Otto
@Sixten - I know, fixed right before your comment.
karim79
+1  A: 
Event.observe($$('.button'), 'click', function(e) {
    // ...
});
Darin Dimitrov