I am not able to catch onclick events in the events object in backbone. I am using the link_to in rails to generate the <a> link. Can someone help me out here?
HTML :
<div id="flash-messages">
<ul>
<li style="opacity: 1;">
<li style="opacity: 1;">
<li style="opacity: 1;">
<div class="alert alert-info">
<a id="consent-link" href="#">See here for more informationnn.</a>
<a class="controls close" aria-hidden="true" data-dismiss="alert" href="#">
<i class="icon-cancel fontLoaded"></i>
</a>
JS code:
module.exports = View.extend({
template: template,
events: {
'click #btnSubmitModal': 'saveConsent',
'click #consent-link' : 'openConsent'
},
openConsent: function(event){
event.preventDefault();
console.log ("asaasagsgsgs");
view = new modalView({model: this.model})
},
From the docs:
So template is a custom property that we can use to point to a template function. Defining this isn't enough, you have to create the actual template by passing the data to template function and append the resulting
HTMLto the views element.Something like:
The event handlers are scoped to (delegated to ) the view's element. Once you append the
HTMLto the view's element (as shown in therendermethod of above example) the events will start working.