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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:40:02+00:00 2026-05-25T21:40:02+00:00

Okay, so I’ve read several other questions regarding Backbone views and events not being

  • 0

Okay, so I’ve read several other questions regarding Backbone views and events not being fired, however I’m still not getting it sadly. I been messing with Backbone for about a day, so I’m sure I’m missing something basic. Here’s a jsfiddle with what I’m working with:
http://jsfiddle.net/siyegen/e7sNN/3/

(function($) {

    var GridView = Backbone.View.extend({
        tagName: 'div',
        className: 'grid-view',
        initialize: function() {
            _.bindAll(this, 'render', 'okay');
        },
        events: {
            'click .grid-view': 'okay'
        },
        okay: function() {
            alert('moo');
        },
        render: function() {
            $(this.el).text('Some Cow');
            return this;
        }
    });

    var AppView = Backbone.View.extend({
        el: $('body'),
        initialize: function() {
            _.bindAll(this, 'render', 'buildGrid');
            this.render();
        },
        events: {
            'click button#buildGrid': 'buildGrid'
        },
        render: function() {
            $(this.el).append($('<div>').addClass('gridApp'));
            $(this.el).append('<button id="buildGrid">Build</button>');
        },
        buildGrid: function() {
            var gridView = new GridView();
            this.$('.gridApp').html(gridView.render().el);
        }

    });

    var appView = new AppView();

})(jQuery);

The okay event on the GridView does not fire, I’m assuming because div.grid-view does not exist when the event is first bound. How should I handle the binding and firing of an event that’s built on a view dynamically? (Also, it’s a short example, but feel free to yell at me if I’m doing anything else that I shouldn’t)

  • 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-25T21:40:02+00:00Added an answer on May 25, 2026 at 9:40 pm

    Your problem is that the events on GridView:

    events: {
        'click .grid-view': 'okay'
    }
    

    say:

    when you click on a descendent that matches '.grid-view', call okay

    The events are bound with this snippet from backbone.js:

    if (selector === '') {
      this.$el.on(eventName, method);
    } else {
      this.$el.on(eventName, selector, method);
    }
    

    So the .grid-view element has to be contained within your GridView’s this.el and your this.el is <div class="grid-view">. If you change your events to this:

    events: {
        'click': 'okay'
    }
    

    you’ll hear your cows (or “hear them in your mind” after reading the alert depending on how crazy this problem has made you).

    Fixed fiddle: http://jsfiddle.net/ambiguous/5dhDW/

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

Sidebar

Related Questions

Okay, so I have my post.php page. If you are not logged in, you'll
Okay, none of the previous questions I have seen with this error seem to
Okay, so the answer to my question might not be the problem but here's
Okay, so I'm not even sure how to ask this question (much less search
Okay I am having some problems with being able to change bitmaps when a
Okay, I am using a custom tab bar (not a tab based app) but
Okay, I haven't used Interface Builder since Xcode 3.x but I remember there being
Okay i know i have to use the JDBC etc, but im not sure
Okay I got some good advice for Mobile Detection but still having an issue
Okay i have this problem with every page i make. im not sure what

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.