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

The Archive Base Latest Questions

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

My events aren’t working as I’d hoped, and I think I know why. When

  • 0

My events aren’t working as I’d hoped, and I think I know why. When the perpage span is clicked, everything renders correctly. But I realized – maybe the events aren’t reattached to the new markup? Could that be why it only works once? (If I click the span with the number 10 in it, 10 items appear like it should be. But afterwards, anything I click doesn’t change anything)

What’s a better way to organize this? Should the template not include the pagination portion? How do I attach backbone events to markup after it has rendered again?

var ListView = Backbone.View.extend({

    initialize: function() {
        var self = this;
        this.collection.bind("refresh", function(){self.render();});
        this.render();
    },

    events: {
        'click ul#perpage span': 'setperpage'
    },

    setperpage: function(event) {
        this.collection.perpageurl = '/perpage/' + $(event.target).text();
        this.collection.fetch();
        this.collection.refresh();
    },

    render: function() {

    template = _.template('\
    <table>\
    <% _(collection).each(function(model){%>\
    <tr><td><%=model.id%></td><td><%=model.name%></td><td><%=model.email%></td></tr>\
    <%}); %>\
    </table>\
    <ul id="perpage">\
    <li><span>5</span></li>\
    <li><span>10</span></li>\
    </ul>\
    ');

        var context = {collection: this.collection.toJSON()};
        $(this.el).html(template(context));
        $('#app').html(this.el);
        return this;
    }
});
  • 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:09:26+00:00Added an answer on May 21, 2026 at 2:09 pm

    try:

    render: function()
    {
        // …
    
        this.delegateEvents();
        return this;
    }
    

    For debugging events in JavaScript use Visual Event. It will tell you which elements have events attached to them.

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

Sidebar

Related Questions

Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
Events are really awesome, and I wouldn't know what I would do without them,
I am attempting to track events when links are clicked on my site in
I've been learning Mootools, but I'm having problems firing custom events. I'm sure it
You might not know this, but pressing the F4 key on a ComboBox makes
I'm struggling with the problem that some of my $('element').onMouseOver() and css-selector:hover aren't working.
Once #theButton is clicked, an alert should be triggered. Why aren't any of the
I read that UILabels aren't meant to respond to touch events, and that I
I'm using FullCalendar jquery pluging in my MVC3 project. For some reason events aren't
I am implementing FullCalendar jquery with asp.net mvc 3. It's working fine but the

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.