i have a list of buttons while are displayed by Handlebars template
<button class="providesolution" id="btn{{issue_id}}" ><small>Post</small></button>
Here the id is unique for all the buttons that i have.
On the Backbone View for the event
events: {
'click .providesolution': 'providesolution',
},
providesolution: function(){
/* how to get the id of the button here when clicked */
}
i have tried in many ways to get id but it shows undefined. Could anyone help me on this? thanks in advance.
backbone passes the event as the first argument to the event handler and you can get the element that caused the event from the event data structure like this:
providesolution: function(e) {
/* how to get the id of the button here when clicked */
var id = e.currentTarget.id;
}
See here and here for other examples.
Unlike in plain Javascript event handlers and with jQuery event handlers, the value of this
is your view, not the element that caused the event, but you can get that element from the event structure.