So, I have one div inside the other - how can I get the distance between them?
I tried something like $('#child').parentsUntil($('#parent')).andSelf()- but it returns an object, not a distance.
$('#child').parentsUntil($('#parent')).andSelf()
PS I need him to press other buttons.
http://api.jquery.com/position/
to get the left distance you can use:
var distLeft = $('#child').position().left;
This will return the distance in pxrelation to the offset parent
px
if you are interested in the page offset of the element than:
var offsLeft = $('#child').offset().left;
http://api.jquery.com/offset/
You can use offset
var childOffset = $('#child').offset(), parentOffset = $('#child').parentsUntil($('#parent')).offset(); var leftDistance =childOffset.left - parentOffset.left; var topDistance = childOffset.top- parentOffset.top;
getBoundingClientRect. a-b
getBoundingClientRect
a-b
https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect
- ?
$('innerDiv').position().left;