Jegan
Jegan

Reputation: 595

Find div position in Mozilla firefox browser

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

Answers (2)

Kartikeya Khosla
Kartikeya Khosla

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.

Fiddle Working Demo

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

Subh
Subh

Reputation: 414

Please check with following code

$(document).ready(function(){
  x=$("#menuFinder").position();
  alert("Top position: " + x.top + " Left position: " + x.left);
});

Upvotes: 0

Related Questions