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

  • Home
  • SEARCH
  • 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 8411551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:26:56+00:00 2026-06-10T00:26:56+00:00

I have super-View who is in charge of rendering sub-Views . When I re-render

  • 0

I have super-View who is in charge of rendering sub-Views. When I re-render the super-View all the events in the sub-Views are lost.

This is an example:

var SubView = Backbone.View.extend({
    events: {
        "click": "click"
    },

    click: function(){
        console.log( "click!" );
    },

    render: function(){
        this.$el.html( "click me" );
        return this;
    }
});

var Composer = Backbone.View.extend({
    initialize: function(){
        this.subView = new SubView();
    },

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


var composer = new Composer({el: $('#composer')});
composer.render();

When I click in the click me div the event is triggered. If I execute composer.render() again everything looks pretty the same but the click event is not triggered any more.

Check the working jsFiddle.

  • 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-10T00:26:57+00:00Added an answer on June 10, 2026 at 12:26 am

    When you do this:

    this.$el.html( this.subView.render().el );
    

    You’re effectively saying this:

    this.$el.empty();
    this.$el.append( this.subView.render().el );
    

    and empty kills the events on everything inside this.$el:

    To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.

    So you lose the delegate call that binds events on this.subView and the SubView#render won’t rebind them.

    You need to slip a this.subView.delegateEvents() call into this.$el.html() but you need it to happen after the empty(). You could do it like this:

    render: function(){
        console.log( "Composer.render" );
        this.$el.empty();
        this.subView.delegateEvents();
        this.$el.append( this.subView.render().el );             
        return this;
    }
    

    Demo: http://jsfiddle.net/ambiguous/57maA/1/

    Or like this:

    render: function(){
        console.log( "Composer.render" );
        this.$el.html( this.subView.render().el );             
        this.subView.delegateEvents();
        return this;
    }
    

    Demo: http://jsfiddle.net/ambiguous/4qrRa/

    Or you could remove and re-create the this.subView when rendering and sidestep the problem that way (but this might cause other problems…).

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

Sidebar

Related Questions

So I have this dilemma, where I have a backbone view that creates a
i have this in the superview: mySubView = [[MySubView alloc] init]; [self addSubview:mySubView]; [mySubView
I have a super pom defined in which I specify a "resources" directory for
I have a super-simple query in a star schema. One fact, two dimensions. I
I have a super fish menu, the delay is set to 800, but when
I have a super class and two subclasses and I want to serialize the
Let's say I have a super type (Shape) and two children (like Square, Circle).
I trying to create inheritance so I can have some super classes with general
Hi i have the following super class class Room: def __init__(self,building,floor,number): self.building=building self.floor=floor self.number=number
do I have to call super in didTurnIntoFault ? I couldn't find any directions

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.