javascript - jQuery - Loop through parent div, get bottom position of last child div -


i trying loop through parent divs , bottom position of last child div.

<main id="swipe-page">     <div class="dragend-page">         <div class="page-content"></div>         <div class="page-content"></div>         <div class="page-content"></div>     </div>     <div class="dragend-page">         <div class="page-content"></div>         <div class="page-content"></div>     </div>     <div class="dragend-page">         <div class="page-content"></div>         <div class="page-content"></div>         <div class="page-content"></div>         <div class="page-content"></div>         <div class="page-content"></div>     </div> </main> 

the bottom position of last page-content div set total height of parent dragend-page div. how this?

$.each($('.dragend-page'), function(i, dragend_page) {     $('.page-content', dragend_page).each(function() {          var p = this.position();          console.log(p.bottom);      }); }) 

this getting bottom position of child divs - not last one. , position function must incorrect because it's returning "this.position not function"

as @rudi mention in comments https://api.jquery.com/position/ returns object containing properties top , left .. can use this

$('.dragend-page').each(function(i, dragend_page) {     var lastdiv = $(this).find('.page-content:last-child');     var bottomposition = lastdiv.position().top +  lastdiv.outerheight(true);     console.log(bottomposition );  }) 

this code output bottom position of last .page-content in each .dragend-page


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -