I have a div with margin auto, in the center (horizontal).
I want to check with jQuery if the div has margin auto.
I tried to get the margin-left with .css()
. Mozilla Firefox shows 0px, and Chrome shows a number of pixels... So with this method I cannot check if the div has margin auto...
What I've tried:
$( document ).ready(function() {
$("#the_margin").append( $("#example").css("margin-left") );
});
// Check with Chrome and Firefox...
// Firefox returns 0px, but Chrome returns a number of pixels
#example {
margin: 0 auto 0;
width: 300px;
border: 1px solid #CCC;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="example">
Some Content
</div>
<div id="the_margin" style="font-weight: bold;">
The left margin is:
</div>
What can I do? Thanks a lot!
EDIT
More clear: HOW CAN I CHECK IF DIV HAS MARGIN AUTO IN JQUERY?