# Set Margins With Javascript?

**URL:** <https://forum.kirupa.com/t/set-margins-with-javascript/208732>\
**Category:** web dev\
**Created:** [December 1, 2006, 6:48pm UTC](https://forum.kirupa.com/t/set-margins-with-javascript/208732 "2006-12-01T18:48:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [December 1, 2006, 6:48pm UTC](https://forum.kirupa.com/t/set-margins-with-javascript/208732/1 "2006-12-01T18:48:29Z")

</div>

Can I set a marginwidth with javascript? I was thinking of something like this:

```auto

<script language="javascript">
function getSize() {
  if(navigator.appName == 'Netscape'){
  	var winWidth = window.innerWidth;
	var midWidth = winWidth/2 - 476;
	var theDiv = document.getElementById("divID");
	theDiv.style.marginLeft = 300;

  }
}
</script>
</head>
<body bgcolor="#193e5e" style="margin: 0px;" onLoad="getSize();">

```

of course that is now working:(
