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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:40:44+00:00 2026-06-15T13:40:44+00:00

I’m building a single web page app using Backbone. My master views depends on

  • 0

I’m building a single web page app using Backbone.

My master views depends on template that will replace the body part of my page based on the URL, but since I must provide an “el” for that view, I wanted it to be the template itself, that would be inserted in the DOM in the “render” or “initialize” method.

But when I call new MyMasterView, the el is undefined since it isn’t present in the DOM at instantiation.

How can I do ?

The only fix I found is to set the el to the existing DOM where I replace the content, and call a .remove().append(the_template) in the render, but I’m not sure it’s the best way.

  • 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-15T13:40:45+00:00Added an answer on June 15, 2026 at 1:40 pm

    We can consider a scenario where you have the following div in the DOM

    <div id="existing">
    
    </div>
    

    This div can be any other element where you wanted to insert the html generated by your view.

    Suppose, you have following template,

    <div id="inside_template">
      <!-- content of the template goes here -->
    </div>
    

    You can specify existing as an el for the view as its already present in the div. The only problem you will have is, if its some tag like body or something, then if you remove it from the view while clearing the view (to prevent memory leaks), it will delete the tag from the dom which might not be desired.

    A solution to that could be, specify existing as el, render view’s html in that el and after that call setElement right after appending the template html to the DOM like,

    render : function() {
      this.$el.html(this.template());
      this.setElement("#inside_template");
    
      // another render method content
    }
    

    What this will do is, it will change the el for the view from existing (or any other DOM element) to inside_template. So while removing the el, inside_template element will be removed, keeping existing element as it is in the DOM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

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.