Last active
December 16, 2015 15:19
-
-
Save aroc/5455534 to your computer and use it in GitHub Desktop.
Keeping direct reference to the element you're inserting into the DOM at render time with Backbone.js
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
// pass in the $parentEl in the options so you can reference it. | |
render: function () { | |
this.$el = $(this.template({ | |
... | |
})).appendTo(this.$parentEl); | |
// Call delegateEvents() afterwards if you have events in your view you want bound to the new this.$el | |
this.delegateEvents(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment