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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:30:35+00:00 2026-05-21T14:30:35+00:00

How should a view’s el be handled? It has to be set, otherwise events

  • 0

How should a view’s el be handled?
It has to be set, otherwise events don’t fire (see here).

But should it be an element that is already on the page?
In my app, I render a (jQuery Templates) template into a Fancybox. What should the el be in that case?

  • 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-05-21T14:30:35+00:00Added an answer on May 21, 2026 at 2:30 pm

    A views el is where all the event binding takes place. You don’t have to use it but if you want backbone to fire events you need to do your rendering work on the el. A views el is a DOM element but it does not have to be a pre-existing element. It will be created if you do not pull one from your current page, but you will have to insert it into the page if you ever want to see it do anything.

    An example:
    I have a view that creates individual items

    window.ItemView = Backbone.View.extend({
        tagName: "li", //this defaults to div if you don't declare it.
        template: _.template("<p><%= someModelKey %></p>"),
        events: {
             //this event will be attached to the model elements in
             //the el of every view inserted by AppView below
            "click": "someFunctionThatDoesSomething"
        },
        initialize: function () { 
            _.bindAll(this, "render");
            this.render();
        },
        render: function () {
            this.el.innerHTML = this.template(this.model.toJSON());
            return this;
        }
    });
    window.AppView = Backbone.View.extend({
        el: $("#someElementID"), //Here we actually grab a pre-existing element
        initialize: function () { 
            _.bindAll(this, "render");
            this.render(new myModel());
        },
        render: function (item) { 
            var view = new ItemView({ model: item });
            this.el.append(view.render().el);
        }
    });
    

    The first view just creates the list items and the second view actually places them on the page. I think this is pretty similar to what happens in the ToDo example on the backbone.js site. I think convention is to render you content into the el. So the el serves as a landing place or a container for placing your templated content. Backbone then binds its events to the model data inside of it.

    When you create a view you can manipulate the el in four ways using el:, tagName:, className:, and id:. If none of these are declared el defaults to a div without id or class. It is also not associated with the page at this point. You can change the tag to something else by using using tagName (e.g. tagName: "li", will give you an el of <li></li>). You can set the id and class of el likewise. Still el is not a part of your page. The el property allows you to do very fine grain manipulation of the el object. Most of the time I use an el: $("someElementInThePage") which actually binds all the manipulation you do to el in your view to the current page. Otherwise if you want to see all the hard work you have done in your view show up on the page you will need to insert/append it to the page somewhere else in your view (probably in render). I like to think of el as the container that all your view manipulates.

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

Sidebar

Related Questions

I want to set hyperlink field in datagrid view. When user clicks on that
I'm trying to build a Chrome browser extension, that should enhance the way the
I am working on an app that will show reverse view from camera. For
I am creating a custom view which will have a bitmap so that user
I have two columns in a location model that should both associate with the
I have a new web app that is packaged as a WAR as part
This should be fairly easy. I'm following along with a fairly outdated video course
I have used a customized list view in which i have added 4 TextView
I have list view which contains 2 buttons and 2 textviews. I change the
I'm trying to have a Table View displaying the content of a generic SQLite

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.