I'm looking to add a click
event to a button without relying on using a template
.
Creating the HTML
<div id="transfer">
<input type="text" placeholder="From Address" id="fromAddress" />
<input type="text" placeholder="To Address" id="toAddress" />
<input type="text" placeholder="Amount" id="amount" />
<input type="button" id="transferMoney" value="Transfer"/>
</div>
Using Backbone View
var TransferView = Backbone.View.extend({
events: {
"click #transferMoney": "sendMoney"
},
sendMoney: function() {
alert();
console.log($("#fromAddress").val());
//this.model.transferMoney();
}
});
var transferView = new TransferView({model: transferMoney});
transferView.render();
However, I'm having an issue where sendMoney()
is not triggered when clicking on the #transferMoney
button.
Is it necessary to always create buttons using template
?