I am trying to bind an event to a \"method\" of a particular instance of a Javascript \"class\" using jQuery. The requirement is that I in the event handler should be able to us
Just use an anonymous function:
$("#myButton").click(function() { myCar.drive(); });
Try this :
$("#myButton").each(function() {
var $btn = $(this);
$btn.on('click',function(){
// Do whatever you want.
});
});
Here you first create a loop to target all #myButton elements (Which is wrong in your example, You should be using Class instead) like:
$(".myButton").each(...
Then we attach the click event handler to all of them.