I am creating a site to manipulate data on multiple tables that are created with jquery.... most tables will be added by the user when they are on the page.
I am also very new to jquery and javascript - so I may be missing something basic here.
I have been able to get buttons created along with the table headers and then added classes to both the table and the button. I would like to be able to add editable rows and columns to each table by clicking on the correlating button, however I cannot find a way to link the two together whether it is by class or some other means.
Here is the code that I have that adds the table:
$("button.agentPerson").on("click", function() {
var $newAgent = $('input.agentPerson').val();
if ($('input.agentPerson').val() !== "") {
$("div.commissionInfo").append("<br/><br/><table><tr><th>Address</th><th>Contract Date</th><th>Production</th></tr><button>New Deal</button></table><br/>");
$("tbody:last-child").addClass($newAgent);
$("button:last-child").addClass($newAgent);
$("select.addToThis").append($('<option>', {
value: $newAgent,
text: $newAgent,
}));
}
});
I have also on the page a dropdown which I would eventually want to be able to hide all tables beside the one chosen. I figure that will be simple once I figure out how to link the two together through classes.
Thank you. If you need any further code please let me know.
I just found the .closest and .parent methods, but I cannot get them to work either.
Here is my most recent attempt to get a button to append to a table.
$("body").on("click", "button", function(event) {
var $theTable = $(this).closest("tbody");
$theTable.append("<tr></tr><tr></tr><tr></tr>");
});