Is it possible to get the data table object reference from a child element
Is it possible to get the data table object reference from a child element

Hi,
I have multiple tables on a page, these tables were initialized as data tables by class, not ID.
So, when a user clicks a row on any of the data tables I want to detect which table they clicked, before applying any changes is this possible? If so, how?
My current code :
$(document).ready(function () {
InitDataTables();
});
function InitDataTables() {
$(".dtTableSearch").DataTable({
});
$(".dtTableSearch tbody").on("click", "tr", function () {
if ($(this).hasClass("selected")) {
$(this).removeClass("selected");
} else {
<<What should I put here to select the parent table??>>.$("tr.selected").removeClass("selected");
$(this).addClass("selected");
}
});
}
I'm open to suggestions if anyone has a better way of doing this?
Many thanks,
Chris
This question has an accepted answers - jump to answer
Answers
Something like this should work:
var table = $(this).closest('table');
Or this to get the Datatable API:
var table = $(this).closest('table').DataTable();
Kevin
Perfect
Thank you Kevin