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);
});
});
I believe the
tableis insidedivNarrative1. In thekeypressthiswill point todivNarrative1and callingcloseston it will not give you the requiredtable. You should usee.targetinstead ofthis.Update: By OP
Heres the js that creates the table
Heres the html on the page