Reputation: 595
I want to find the div position for some calculation. And I am trying the following scenarios it will works in Chrome browser
$('#menuFinder').offset().top;//First
document.getElementById('menuFinder').getBoundingClientRect();//Second
$("#menuFinder").position();//Third
But both these codes are not worked in Mozilla browser.
Upvotes: 1
Views: 305
Reputation: 18883
You can use .position() in jquery :-
var position = $('#menuFinder').position(); //here position will be object having .left and .top properties.
position.left and position.top will have desired coordinates of a div.
EDIT :-
Complete Code :-
$(document).ready(function(){
var position = $('#menuFinder').position();
$('span').text("Left:" + position.left + " Top:" + position.top);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div id="menuFinder">Test</div>
<span></span>
Upvotes: 2
Reputation: 414
Please check with following code
$(document).ready(function(){
x=$("#menuFinder").position();
alert("Top position: " + x.top + " Left position: " + x.left);
});
Upvotes: 0