Skip to content

Instantly share code, notes, and snippets.

@jorgepedret
Created October 18, 2013 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgepedret/7045892 to your computer and use it in GitHub Desktop.
Save jorgepedret/7045892 to your computer and use it in GitHub Desktop.
Snippet to extend Backbone's view to avoid the empty wrapping element when rendering
/*
* Helper method to avoid Backbone wrapping empty element
*/
Backbone.View.prototype.replaceElement = function (html) {
if (typeof html === "string") {
html = $(html);
}
this.$el.replaceWith(html);
$(this.el).undelegate();
this.setElement(html);
this.delegateEvents();
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment