Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  115] [ 5]  / answers: 1 / hits: 88684  / 11 Years ago, sat, february 8, 2014, 12:00:00

I know there are a lot of posts about this, but I can't find an answer to my specific problem.


I would like to make a JS variable the value of an HTML attribute:


<script> var screenWidth = screen.width </script> 

<img src="images/title.png" width="VARIABLE HERE" style="margin-top: 3%"`

"VARIABLE HERE" is where I would want the screenWidth variable to go. What is the best of going about this?


More From » html

 Answers
7

This should work:



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

[#72650] Friday, February 7, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;