Return the right margin of a <div> element:
alert(document.getElementById("myDiv").style.marginRight);
<!DOCTYPE html> <html> <head> <style> #myDiv {/* w ww . j ava 2 s.co m*/ border: 1px solid #FF0000; } </style> </head> <body> <div id="myDiv" style="margin-right:5cm;">This is a div.</div> <br> <button type="button" onclick="myFunction()">Return right margin</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = document.getElementById("myDiv").style.marginRight; } </script> </body> </html>