Processing math: 100%

Backbone.JS View Remove()

The Backbone.JS View Remove() method removes a view from the DOM.

Syntax:

View.Remove()

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<div id="A"><button>Just a Click</button></div>
<script type="text/javascript">
var X = Backbone.View.extend({
events: {'click': 'removal'
},
removal: function () {
this.remove();
document.write("Oops, you removed the View. <br>");
document.write("View (after removal): ",$('#A').length);
},
render: function () {
this.$el.html('<button>Just a Click</button>');
},
initialize:function(){this.render();}
});
var Y = new X({el: '#A'});
</script>
<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> <div id="A"><button>Just a Click</button></div> <script type="text/javascript"> var X = Backbone.View.extend({ events: {'click': 'removal' }, removal: function () { this.remove(); document.write("Oops, you removed the View. <br>"); document.write("View (after removal): ",$('#A').length); }, render: function () { this.$el.html('<button>Just a Click</button>'); }, initialize:function(){this.render();} }); var Y = new X({el: '#A'}); </script>
  

  
Example  
  
  
  
  
  

Output:



Example