Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:14:20+00:00 2026-06-13T13:14:20+00:00

I am learning backbone routes. I just built a small app using backbone. But

  • 0

I am learning backbone routes. I just built a small app using backbone. But the routes are not working. I am getting this error in console

Uncaught TypeError: Cannot read property 'el' of undefined

here is my code

$(function () {
/****************************/
var documents = [
    new Backbone.Model({
        title: 'Title One',
        content: 'This is content for JS module'
    }),
    new Backbone.Model({
        title: 'Title Two',
        content: 'Module Systems Module Systems Module Systems Module Systems Module Systems'
    })
];

var contentsView = Backbone.View.extend({
    tagName: 'ul',
    render: function () {
        _(this.collection).each(function (document) {
            this.$el.append(new DocumentListView({model: document}).render().el);
        }, this);
    }
});

var DocumentListView = Backbone.View.extend({
    tagName: 'li',
    render: function () {
        this.$el.html(this.model.get('title'));
        return this;
    }
});

var DocumentRouter = Backbone.Router.extend({
    routes: {
        'contents': 'contents'
    },
    contents: function () {
        $('body').html(new contentsView({collection: documents}).render().el);
    }
});

var router = new DocumentRouter();
Backbone.history.start();

router.navigate('contents', {trigger:true});
/****************************/
});

This is the line where above error occurs according to console message

$('body').html(new contentsView({collection: documents}).render().el);

how can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:14:21+00:00Added an answer on June 13, 2026 at 1:14 pm

    You should return this from your contentsView render function.

    var contentsView = Backbone.View.extend({
            tagName: 'ul',
            render: function () {
                _(this.collection).each(function (document) {
                    this.$el.append(new DocumentListView({model: document}).render().el);
                }, this);
             return this;
            }
        });
    

    And if you mean to append contentsview to body, use something like this
    $(‘body’).append(new contentsView({collection: documents}).render().$el);

    If contentsView is the only contents meant for the body tag, use a construct like this

    var contentsView = Backbone.View.extend({
                el : 'body',
                tagName: 'ul',
                render: function () {
                    _(this.collection).each(function (document) {
                        this.$el.append(new DocumentListView({model: document}).render().el);
                    }, this);
                 return this;
                }
            });
    contentsView.render();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple Backbone app for learning purposes. I'm just creating a time
I just started learning Backbone.js, and have been working on (what else) a simple
This may seem like a really off-the-wall question, but I've been learning how Backbone.js
Learning C at University. This is not a homework, but I was trying to
I've been spending the weekend learning Backbone.js and while building a simple app an
I am learning backbone. I am trying to use on event for change. But
I'm building a web app with Backbone.js (I'm not tied to Backbone yet though).
Learning ruby on rails, playing around with routes and path methods. I have built
I'm still learning Backbone but it is my understanding that it should handle updating
I'm learning Backbone.js and got stuck on this simple example. Could you explain what's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.