Kirill Kaysarov
Kirill Kaysarov

Reputation: 13

Multiple el in Backbone.View

For example i have:

Job.Views.Response = Backbone.View.extend({
el: '.ra-response-button',
    events: {
      "click" : "alert"
    },

    alert: function() {
       console.log(this.$el);
    }; 
)};

And i have multiple buttons (BUTTON). I want that work only with clicked button. How i can do that?

Upvotes: 0

Views: 711

Answers (1)

Codrin Eugeniu
Codrin Eugeniu

Reputation: 1383

Change the el to the parent element of the buttons, then do something like this

 <div id="buttonWrapper">
    <input type="button" id="button1" />
    ... snip ...
 </div>

View:

  Job.Views.Response = Backbone.View.extend({
     el: 'buttonWrapper',
     events: {
      'click #button1': 'eventHandler1', 
      'click #button2': 'eventHandler2',
      ... And so on...
   }

Upvotes: 2

Related Questions