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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:10:16+00:00 2026-05-30T22:10:16+00:00

I am creating tables on button click and that works great. I then have

  • 0

I am creating tables on button click and that works great. I then have have a hotkey to add extra rows to those tables. I need to get the parent id of the table where the cursor is but it keeps giving me undefined. I can get the parent div id ok but when I put table in it gives me undefined. Any help would be appreciated

$(document).ready(function() {
    $("#divNarrative1").keypress(function(e){    
        alert(e.target.id);
        var msgId = $( this ).closest( 'table' ).attr( 'id' );
        alert(msgId);
    });

});
  • 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-30T22:10:18+00:00Added an answer on May 30, 2026 at 10:10 pm

    I believe the table is inside divNarrative1. In the keypress this will point to divNarrative1 and calling closest on it will not give you the required table. You should use e.target instead of this.

    $(document).ready(function() {
        $("#divNarrative1").keypress(function(e){    
            alert(e.target.id);
            var msgId = $(e.target).closest('table').attr('id');
            alert(msgId);
        });
    
    });
    

    Update: By OP

    Heres the js that creates the table

         // Insert HTML table 
    function InsertTable() {
         var div = document.getElementById('divNarrative1'); // table reference 
    
        div.focus();
    
        document.getElementById("hfProjectBoxNumber").value = Number(document.getElementById("hfProjectBoxNumber").value)+ 1;
        document.getElementById("hfBillTextNumber").value = Number(document.getElementById("hfBillTextNumber").value)+ 1;
    
        var projdiv = "Projectbox" + document.getElementById("hfProjectBoxNumber").value
    
         //create table
         var tbl = document.createElement('table');
         tbl.id = projdiv;
         tbl.width = "570px";
         tbl.setAttribute("table-layout", "fixed");
         tbl.setAttribute("border", "1");
         tbl.setAttribute("height", "50px");
         tbl.border = 1;
    
         //create header row
         var oRow = tbl.insertRow(-1);
         var oCell = oRow.insertCell(-1);
         oCell.width = "570px";
         oCell.setAttribute("colspan", "2");
         oCell.setAttribute("align", "center");
         oCell.innerHTML = projdiv;
    
         //create coumns
         var oRow = tbl.insertRow(-1);
         var oCell = oRow.insertCell(-1);
         oCell.width = "430px";
         oCell.innerHTML = "DESCRIPTION";
         oCell.setAttribute("align", "center");
    
         var oCell2 = oRow.insertCell(-1);
         oCell2.width = "140px";
         oCell2.innerHTML = "AMOUNT";
         oCell.setAttribute("align", "center");
         div.appendChild(tbl);
         return false;
     }
    

    Heres the html on the page

        </div>
            <asp:Button ID="btnEditNarr" runat="server" Text="Edit Narrative" />
            <input type="button" value="Clear all Content" onclick="clearBilltextbox();"/>
            <input type="button" value="Save Content" onclick="getallcontent();"/>
    
    </asp:Panel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating winForm app,In that Onbutton click i gather Data Tables from of Two
I have a dynamic form that i am creating in php then i have
I'm creating a custom table that has a button which allows a user to
I need UNION two tables with creating new field, where 1 for first table,
I'm creating a map using Google Fusion Tables. It has several layers that are
i am creating the textboxes dynamically using jquery on a button click. <table width=100%
I have a slight problem with creating a button on the server side code.
I'm creating a dynamic form with radio buttons in front of each rows that
I am creating dropdown in iphone app i have place the button on top
I am creating a web page that has 3 basic elements, select box, button,

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.