Created
October 18, 2013 18:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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