Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  152] [ 6]  / answers: 1 / hits: 19867  / 9 Years ago, mon, september 14, 2015, 12:00:00

I have div with margin:auto; and I need get only margin-left size value using javascript :)



//css
.test{
margin: auto;
width: 100px;
height: 100px;
outline: 1px solid red;
}


// html
<div class=test>Test</div>


Live example


More From » jquery

 Answers
5

Use this:



1) With jQuery



var left = $(.test).offset().left;


2) Or, second version is that:
Replace your div to <div class=test id=test></div>, and use this js.



var left = document.getElementById(test).offsetLeft;

[#65075] Friday, September 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katieh

Total Points: 692
Total Questions: 104
Total Answers: 104

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;