Uncaught TypeError: Unable to call replace method from null

If I find "_.template ($ ('# pranks-list'). Html ())" on the Chrome JS console, it also works

>> _.template($('#pranks-list').html())
function (a){return e.call(this,a,b)}

app.js // Views

window.PranksListView = Backbone.View.extend({

    template: _.template($('#pranks-list').html())
});

Index.html                          
      

  <script type="text/html" id="pranks-list">
    <li><a href='#pranks/<%= id %>'><%= name %></a></li>
  </script>

  </body>

Why am I getting this error on this line?

template: _.template($('#pranks-list').html())
+5
source share
1 answer

It's hard to say without seeing all the code, but you are probably trying to run _.template($('#pranks-list').html())before creating dom and node. This is usually good practice for rendering a template during rendering, when you have ready-made template variables:

_.template($('#pranks-list').html(), {id: 'foo', name: 'bar'});
+15
source

All Articles