user3142443
user3142443

Reputation: 61

use javascript in a html tagg

I have these codes:

<script type="text/javascript">
var screenWidth = window.screen.width;
var width_sides = (screenWidth - 980) / 2; 
</script>

<div id="not_important" width=""></div>

I want to set the width of the div equal to the result from the equation inside the javascript tagg. How can I do that?

Thanks

Upvotes: -1

Views: 46

Answers (1)

Maksim Gladkov
Maksim Gladkov

Reputation: 3079

<div id="not_important" width=""></div>

<script type="text/javascript">
  var screenWidth = window.screen.width;
  var width_sides = (screenWidth - 980) / 2; 
  document.getElementById('not_important').style.width = width_sides;
</script>

Upvotes: 1

Related Questions