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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:52:25+00:00 2026-06-05T02:52:25+00:00

I am trying around with Backbone.js and get along so far, but I have

  • 0

I am trying around with Backbone.js and get along so far, but I have got a problem.

Lets say I got a root element and a child element.

When the document loads, I create 3 “root” instances. The root instance appends a tag.
Each root instance creates one child instance which creates a

  • tag in the ul tag.

    Now I would like the child instance to attach and onclick event to the

  • tag. Unfortunately, it won’t work.

    I created a fiddle:

    http://jsfiddle.net/Fluxo/sEjE5/17/

    var child = Backbone.View.extend({
        template: _.template('<li>Item '+count+'</li>'),
        events: {
            'click li': function() {
             alert('listitem Click Child Element');   
            }
        },
        initialize: function() {
          _.bindAll('render');  
         this.render();   
        }, render: function() {
            this.$el.html(this.template())
        }
    });
    
    var root = Backbone.View.extend({
        template: _.template('<div><h3>List</h3><p /><ul></ul><hr />'),
        events: {
            'click li': function() {
             alert('listitem Click - Root Element');   
            }
        },
        initialize: function() {
            _.bindAll('render');
            this.render();
        },
        render: function() {
            this.$el.html(this.template());
            $('body').append(this.el);
            var item = new child();
            this.$el.find('ul').append(item.$el.html());
    
        }
    });
    

    The events created in the root element will fire, but not the ones in the child element.

    Am I doing anything wrong?

    • 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-05T02:52:26+00:00Added an answer on June 5, 2026 at 2:52 am

      You’re doing two things wrong.

      First of all, your child is an <li>, it doesn’t contain an <li>:

      template: _.template('<li>Item '+count+'</li>'),
      events: {
          'click li': ...
      },
      

      so your click li event won’t do anything. Events are bound to the view’s el using delegate:

      delegateEvents delegateEvents([events])

      Uses jQuery’s delegate function to provide declarative callbacks for DOM events within a view. […] Omitting the selector causes the event to be bound to the view’s root element (this.el).

      So if you want to bind a click handler directly to the view’s el rather than one of its children, you want to leave out the selector:

      events: {
          'click': ...
      }
      

      The next problem is that you’re not actually inserting the child element into the DOM, you’re copying the HTML:

      this.$el.find('ul').append(item.$el.html());
      

      By appending item.$el.html() instead of item.el, you’re grabbing the correct HTML as a string and inserting that HTML but you lose the events in the process; the events are bound to the DOM object, item.el, not to the HTML string. You can fix this by appending item.el:

      this.$el.find('ul').append(item.el);
      // Or you could say, the two approaches are the same
      this.$('ul').append(item.el);
      

      Demo: http://jsfiddle.net/ambiguous/K76JM/ (or http://jsfiddle.net/ambiguous/kFxHQ/)

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

    Sidebar

    Related Questions

    Trying to get my head around backbone.js. This example is using Backbone Boilerplate and
    I'm still trying to get my head around Backbone.js I've watched some screencasts and
    I am just messing around trying to make a game right now, but I
    So I am a little confused, I have been looking around trying to determine
    i've been messing around trying figure this out myself but its taking a while..
    I'm trying to write an interface around my program (using qt). Basically I have
    I have been using Backbone on a new project and so far have loved
    I was searching around trying to solve a problem I am having with WCF.
    I'm trying to learn how to use backbone.js. Problem is that a tutorial I'm
    I've been mucking around trying to get combination of xp:fileUpload and xe:multiImage for display

    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.