Skip to content
Advertisement

Get the position from div top from last elment in scrollable div with jQuery

How can i get the position from div top from the last elment in a scrollable div with jQuery? I have tried this but it doesnt work:

let bES = $(id).children().last().scrollTop()
console.log(bES)

Advertisement

Answer

You can use the .position() method to read its top property :

let bES = $('#content').children().last().position().top
console.log(bES)
div {
  height: 60px;
  overflow: scroll;
}

input {
  display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="content">
  <input value="123">
  <input value="456">
  <input value="789">
</div>
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement