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 8134057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:52:35+00:00 2026-06-06T09:52:35+00:00

We are working on a web app with the Django framework and we are

  • 0

We are working on a web app with the Django framework and we are using Backbone.js for MV decomposition. We have a view and call render on it, which swaps out a div#main with new content, like this:

var GoalListView = Backbone.View.extend({
el: $('#main'),

template: _.template($("#swap").html()),

render: function() {
  $(this.el).html(this.template());
  return this;
}

});

This works as we expect (changing the page with the contents of the template), but in the next View we create, we are unable to access any of these new DOM elements.

 el: $('#newId') 

gives us undefined, even though we have an element with id newId in the template we swapped in. The template swap has already occurred at this point though, so why are we unable to access the new elements?

EDIT: Thanks, I agree it’s a timing issue. But what about for events?

events: {
    'keypress #goal-entry': 'createOnEnter'
 },

Then there’s no option to search the DOM for the elem to attach the event to, right?

  • 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-06T09:52:36+00:00Added an answer on June 6, 2026 at 9:52 am

    You have to be sure that $('#newId') is in the DOM already if you are assigning it to el. In our case, if you insert element used for the second view, you don’t need to define it initially but must pass it to initialize():

    var SomeView = Backbone.View.extend({
      // do NOT define el or $el or id here
      initialize: function($el) {
        this.$el = $el;
        ... go on do more things...
      }
    });
    

    and then init the second view from wherever you need in the app:

    var someView = new SomeView($('#someID'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web-app using Django 1.3 and Python2.6. I have to
Using Visual Studio 2008 and VB.Net: I have a working web app that uses
I am using working on web app which had a DIV in which latest
Im working on an web app using c#. I have in my code the
i'm currently working in a web app and i'm using django-jquery, and when i
Gurus of SO I have a working web app which works well enough with
I am working on a web app using C# and asp.net I have been
I've been working on a web app using Django, and I'm curious if there
I'm working on a simple webservice in django. This is my first web app
I'm working on a web app that tracks workers check in and check out

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.