Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  10] [ 6]  / answers: 1 / hits: 40524  / 12 Years ago, mon, august 6, 2012, 12:00:00

This code should set an elements height; however no style gets added. Am I missing something obvious?



function setGround() { 
document.getElementById('content').style.height = '40px';
}

document.onload = setGround;


The HTML is quite basic:



<!DOCTYPE html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=utf-8 />
<title>Template</title>
<link rel=stylesheet type=text/css href=css/default.css/>
<link rel=stylesheet type=text/css href=css/orange.css/>
<script type=text/javascript src=javascript/detect-css.js></script>
</head>

<body>
<header>
<div id=logo></div>
</header>
<section id=sidebar><p>sf </p>
</section>

<section id=content><p>sf </p>
</section>

</body>
</html>


Thank you for your help!


More From » html

 Answers
17

Don't use document.onload use window.onload instead.



See http://jsfiddle.net/mowglisanu/r6NzE/


[#83810] Sunday, August 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emilianoc

Total Points: 568
Total Questions: 109
Total Answers: 99

Location: Oman
Member since Sat, Jan 7, 2023
1 Year ago
;