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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:19:19+00:00 2026-06-07T05:19:19+00:00

I am currently populating a list dynamically based on some web calls. When these

  • 0

I am currently populating a list dynamically based on some web calls. When these calls return I use an HTML template to add another item to the list based on the call response. I also am trying to attach some events to these objects using jQuery, but when I generate the items it seems like only the last item generated has the appropriate events firing.

So here is the code:

The javascript generates the html string and the adds it to the list:

List.innerHTML += html;

The html is generated using moustache.js and renders properly, I set the id in the template before adding it.

The template has this form:

var template = '<li style="width:400px; height:100px" id="{{id}}"  ><img src="{{source}}" style="float:left"/>{{title}} <button id="{{id}}button">Delete</button></li>';

Where all the elements are replaced appropriately.

Then I try to attach a click event to the button and a double click event to the entire list object:

$('#' +id +'button').bind('click', function() {
       //SOME STUFF GOES HERE
     });

$('#' +id +'button').bind('dblclick', function() {
     //MORE STUFF GOES HERE
     });

Im not sure why the event wouldnt attach to each object, am I missing something?

Thanks!

  • 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-07T05:19:22+00:00Added an answer on June 7, 2026 at 5:19 am

    The DOM might not have been updated on the browser by the time you add the click handlers. You have a couple options:

    1. Use delegated binding (using .on)
    2. Attach the events before adding them to the DOM

    Example 1:

    $('body').on('click', '#' +id +'button', function () { /* foo */ });
    

    Example 2:

    $('#' +id +'button', myHtml).on('click', function () { /* foo */ });
    List.append(myHtml);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this code for populating a list of comments to return: foreach
Is there some obvious way to add a separator to the list of options
I'm having some weird issues with dynamically populating a table in Javascript. Behold the
I'm currently reading in a list of tables in a SQL database and populating
I want to dynamically hide/show some of the columns in a NSTableView, based on
I currently have objects populating the screen randomly and bouncing around the stage. The
I am populating my Google chart using JSON currently, but I need to customize
Currently I am using HTML files for parts of my user interface. I display
I am currently populating an NSTableView through the controller (MVC design pattern) where I
Currently I'm populating my tableviewcells with the contents of multiple arrays representing a name,

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.