У меня есть две таблицы в первой таблице, ее возвращаемая позиция (). Top отлично, но когда я нажимаю на вторую таблицу, тогда ее возвращаемое значение такое же, как и в первой таблице, как я могу это исправить?
Почему обе таблицы position (). top вернуть то же самое?
$(function() {
$('tr').click(function() {
offsetTop = $(this).position().top;
console.log(offsetTop);
});
});
.myDiv {
overflow-y: auto;
height: 250px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="myDiv">
<h2>Table 1</h2>
<table class="table table-bordered">
<tbody>
<tr>
<td>Click here this is first table, its return -1 in console</td>
</tr>
</tbody>
</table>
<h2>Table 2</h2>
<table class="table table-bordered">
<tbody>
<tr>
<td>Click here this is second table, its also return -1 in console why? how can i fix it? how can i get exactly position of this element?</td>
</tr>
</tbody>
</table>
</div>