Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling CSS styling from a function

Status
Not open for further replies.

bnther

Programmer
May 22, 2010
1
US
I've got a background image that is kind of bandwidth heavy so I'm using body onload to load it last. What I haven't figured out is how to apply the CSS styling that I would normally use to make the image expand and contract with the browser size.

CSS code:
html, body{ width:100%; height:100%; overflow:hidden;}
#backgroundFill{position:absolute; z-index:1; width:100%; height:100%;}

html WITHOUT javascript:
<body><img src="wall.jpg" id="backgroundFill" />

html WITH javascript;
<body onload="setBackground()">

javascript:
function setBackground(){
document.body.style.backgroundImage='url(wall.jpg)';
}

I've tried:
document.getElementById('backgroundFill');

Any thoughts would be appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top