Backbone with events definitions
Define events in Backbone View
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<div id="container"></div>
<br/>Button not from Backbone: <button id="btn3">Button2</button>
<script type="text/template" id="my_template">
<input id="name" >
<button id="btn1" data-id="123465">Button5</button>
</script>
CSS
#container {
color: red;
font-size: 26px;
}
JavaScript
var AppView = Backbone.View.extend({
el: '#container',
initialize: function(options) {
this.render();
},
render: function() {
var template = _.template($("#my_template").html());
this.$el.html(template);
},
events: {
"click button": "event_handler",
"blur #name": "event_handler"
},
event_handler: function( event ){
alert(event.target);
}
});
var appView = new AppView();