Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get margin-left using jquery not working in firefox

Tags:

jquery

firefox

The below code is working fine in chrome but not in firefox. the alert shows proper margin in chrome while in firefox it always shows 0px.

HTML:

<div class="center">14</div>

CSS:

.center {
    margin: 0 auto;
    width: 200px;
    background-color: #ccc;
}

JQuery: I am using latest jQuery Library

$(function(){
    var center = $('.center').css('margin-left');
    alert(center);
});

Please see the jsfiddle in both firefox and chrome: http://jsfiddle.net/vtbuz/2/

like image 372
kp singh Avatar asked Jan 24 '14 08:01

kp singh


1 Answers

It's a solution:

var center = $('.center').offset().left;

by using this we can get the proper left position relative to document.

like image 112
kp singh Avatar answered Nov 03 '22 02:11

kp singh