CodesJava

Easy learning with example program codes

Backbone.js DelegateEvents()


The Backbone.JS View DelegateEvents() method binds elements to the specified DOM elements with callback methods to handle events.

Syntax:

DelegateEvents (events)   

Parameters:
events: This parameter is used to specify the required events.

Example:

<!DOCTYPE html>  
<html>
<head>  
<title>Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" 
type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" 
type="text/javascript"></script>  
</head>  
<body>  
<div id="A"></div>  
<script type="text/javascript">  
var X = Backbone.View.extend({  
events: {'click': 'delegate'},  
delegate: function () {  
this.remove();     
document.write("HELLO WORLD!!");  
},  
render: function () {  
this.$el.html('<button>Just a Click</button>');  
},  
initialize:function(){this.render();}  
});  
var Y = new X({el: '#A'});     
Y.delegateEvents();  
</script>  
</body>  
</html>

Output:



Example






Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki