I am using jQuery and my goal is to get the id of next table. I will simplify the code here:
The simplified HTML looks like this:
<div>
<img src="png.png" class="exportIcon" alt='' onClick="tableExport()">
<table class="table tablesorter" id="tableHourlyT"><tr><td></td></tr></table>
</div>
And I then have the following function:
<script>
function tableExport(){
tableID = $(this).next('table').attr("id");
alert(tableID);
}
</script>
But the alert says "undefined" and in fact I cant even do anything with the table, I tried hiding it etc. It just doesn't find it. I also tried replacing the next()
with closest()
but I still had the same result. What I need to do is always when the function is called, get the id of the closest following table from that element (clicked image/button).