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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:46:07+00:00 2026-05-26T00:46:07+00:00

The following code works, in so much that it creates the table and appends

  • 0

The following code works, in so much that it creates the table and appends the rows.

However, I’ve attached a click event to the dynamically created button that resides in <tfoot> and it doesn’t work. It doesn’t seem to call the createNewIssue function and it doesn’t generate any Firebug errors. I altered it to just throw up a simple alert, but that doesn’t work either.

I’m pretty new to jquery, so if there’s a better way to do this, then great, but hoping someone will at least be able to help me understand why my tfoot button isn’t working…

First…

$(document).ready(function() {
  //add-section works
  $('#add-section').click(function() {
    createNewSection();
  });

  //this does not work      
  $('input[id^=add-issue-]').click(function() {
    alert($(this).attr('id')); //put this in and it fails

        //this is what I really want it to do:
        var issueid = $(this).attr('id');
        createNewIssue(issueid);
  });

});

This is the createNewSection function, which works:

function createNewSection() {
    var sectioncount = $('input.section-title').length;
    var issuecount = $('input.issue-title').length;
    var newsection = $('input#add-section-textfield').val();

    //Add section entry to table
    var sinput = document.createElement("input");
    sinput.setAttribute("type", "text");
    sinput.setAttribute("name", "section["+sectioncount+"][title]");
    sinput.setAttribute("id", "section-"+sectioncount+"-title");
    sinput.setAttribute("value", newsection);

    //Issue title input
    //Add section entry to table
    var iinput = document.createElement("input");
    iinput.setAttribute("type", "text");
    iinput.setAttribute("name", "add_issue_"+sectioncount);
    iinput.setAttribute("id", "add-issue-"+sectioncount);
    iinput.setAttribute("value", "");

    //Button to add issue entry to table
    var issuebutton = document.createElement("input");
    issuebutton.setAttribute("type", "button");
    issuebutton.setAttribute("name", "add_issue_"+sectioncount);
    issuebutton.setAttribute("id", "add-issue-"+sectioncount);
    issuebutton.setAttribute("value", "Add Issue");

    var sTable = $('<table>').attr('id', 'section-'+sectioncount).appendTo('#sections');
    var sTbody = $('<tbody>').appendTo(sTable);
    var sTrow = $('<tr>').appendTo(sTbody);
    var sTcell = $('<td>').attr('colspan', 2).html(sinput).appendTo(sTrow);
    var sTfoot = $('<tfoot>').appendTo(sTable);
    var sTfootRow = $('<tr>').appendTo(sTfoot);
    var sTfootCell = $('<td>').html(iinput).appendTo(sTfootRow);
    var sTfootCell2 = $('<td>').html(issuebutton).appendTo(sTfootRow);
}

Eventually, I’m trying to get the createNewIssue function to add a row (containing a nested table) to <table id="section-...>, but for now, I’m just trying to get it to throw an alert with the id of the parent table…

function createNewIssue(issueid) {
    var sTable = $(id).parent().parent().attr('id');
    alert(sTable);
}
  • 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-26T00:46:08+00:00Added an answer on May 26, 2026 at 12:46 am

    You probably want to use jQuery’s .live() event binding as the items are dynamically added to the DOM and won’t be attached to after the initial binding call. e.g.

    $('input[id^=add-issue-]').live('click', function() {
      alert($(this).attr('id')); //put this in and it fails
    
      //this is what I really want it to do:
      var issueid = $(this).attr('id');
      createNewIssue(issueid);
    });
    

    .live() tells jQuery to not only bind to elements already on the page, but keep an eye out for future elements matching your selector as well.

    Update

    As of jQuery v1.9, .live() is no longer available and has since been replaced with .on(). If you’re using jQuery >= 1.9, please use the following instead:

    $(document).on('click', 'input[id^="add-issue-"]', function(e){
      alert($(this).attr('id'));
    
      var issueId = $(this).attr('id');
      createNewIssue(issueId);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which works fine. However, I only want to return
I have code that looks like the following, which works fine for displaying the
The following code works great in IE, but not in FF or Safari. I
The following code works for 90+ % of global security groups, but for one
The following html code works in Firefox, but for some reason fails in IE
I have the following code which works just fine when the method is POST,
I was loading an image resource with the following code and it works fine
Given the following code,the hover function works correctly, but when clicked, loses the clicked_no_event_box
I've written PL/SQL code to denormalize a table into a much-easer-to-query form. The code
Consider the following JavaScript code, meant to create an 8x8 table inside of a

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.