Search code examples
javascriptjquerybackbone.js

getting undefined after trying to find on an element generated by template


I have the following code in one of my render function:

$newItemView = this.template( {item:this.model} );
$newItemView.find('.other-items-from-same-shop');

why is it that I am always getting an undefined when calling find on newItemView? newItemView is there.

My template can be seen here, When I try to print out $newItemView it prints out the generated html from the template.


Solution

  • I'm assuming you're using jQuery so try this:

    $newItemView = $(this.template( {item:this.model} ));
    $newItemView.find('.other-items-from-same-shop');