javascript - Position returning 0 on div position static -


i trying use jquery's position method obtain position of div. div has default property position property. reason returns object {top: 0, left: 0}

the html particular div shown below:

<div class="col-xs-3" id="increased-width">             <div id="standards">                 <label><strong>my energy standards</strong></label>                 <a class="btn" data-toggle="modal" data-target="#energystandardmodal"><span class="glyphicon glyphicon-info-sign"></span></a>                 <br />             </div>             <div id="years">                 <h5><strong>my study periods (in years)</strong></h5>                 <div id="col-1" class="altstudyperiod"></div>                 <div id="col-2" class="altstudyperiod"></div>                 <div id="col-3" class="altstudyperiod"></div>                 <div id="col-4" class="altstudyperiod"></div>             </div>         </div> 

the jquery code shown here:

$(document).ready(function () {     standarddiv = $("#standards").position();     console.log(standarddiv); }); 

i tried using offset() method returns same values. however, particular not located @ origin of webpage (0,0)

here's fiddle might explain things.

i've used code, added css clarify things.

borders have been added divs can seen, , spacer div above col-xs-3 div push down.

the col-xs-3 parent/holder div needs have css position: relative.

note using .position() on #standards div gives position relative container div position: relative - "0" top (of container div).

using .offset() on #standards div gives position relative window - "59" top (of window).

js

$('.putmehere').html( "#standards position.top using .position(): " + $("#standards").position().top );  $('.putmehere2').html( "#standards position.top using .offset(): " + $("#standards").offset().top ); 


edit: if wish, can add .spacerdiv10 above #standards div , see happens top measurements.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -