Javascript variables in HTML attributes

This should work:

<script>var screenWidth = screen.width;</script> 
...
<img src="https://stackoverflow.com/questions/21643920/images/title.png" onload="this.width=screenWidth;" style="margin-top: 3%">

Leave a Comment