documentcloud/backbone — pull request #675 by jgoldberg (2011-10-17 06:31:44+00:00)
Title: Adds helper method to Backbone.View for retrieving sub-elements of $(this.el).

Adds helper method to Backbone.View for retrieving sub-elements of $(this.el).

I constantly find myself having to write code like this:

$(this.el).find('.stream');

$(this.el).find('input[type="name"]').keydown( function () { ... });

Using this.el is awkward. I added a utility method for looking up sub-elements of this.el:

this.find('.stream');
this.find('input[type="name"]').keydown(function () { ... });

find() also caches element references based on selector strings for faster lookup.