Skip to content

Instantly share code, notes, and snippets.

@aroc
Last active December 16, 2015 15:19
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 aroc/5455534 to your computer and use it in GitHub Desktop.
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
// 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