Refer to Backbone view's child element

backbone.js, javascript, underscore.js

Solution

Backbone Views expose a dollar `$` function that will use jQuery under the covers, but within the context of the view itself.

this.$('.child_element_of_my_view_template')

This will work even if the view is detached (`$el` not in DOM) but will obiouvsly only work by the time the element you want to select exists within the view (appended to `$el`).

This means that you can safely use it after the first line of your `render` function.

Problem

Having just rendered a view like so: ``` render: function() { this.$el.html(this.template(this.model.toJSON())); return this; }, ``` How can I refer to one of the template's child elements and apply a jQuery function to it?

Original source