Example html:
Code: Select all
<div id="dv1">div 1</div>
<div id="dv2">div 2</div>
Code: Select all
<div id="dv1">div 1</div>
<div id="dv2">div 2</div>
Code: Select all
<div id="dv1">div 1</div>
Some text ...<br>
https://coursesweb.net/
<div id="dv2">div 2</div>
<script>
var dist_ho = Math.abs($('#dv1').offset().left - $('#dv2').offset().left); // horizontal distance
var dist_ve = Math.abs($('#dv1').offset().top - $('#dv2').offset().top); // vertical distance
// test
alert('dist_ho: '+ dist_ho + ' - dist_ve: '+ dist_ve);
</script>