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!

Background Images with JavaScript & CSS

Status
Not open for further replies.

giles100

Technical User
Feb 18, 2007
10
GB
Hi

I’m in need of some help ... I would like to be able to set a background image using a onload javasacript along the lines of

PHP:
document.body.stylebackgroundImage = url()

and then position it with css.. something like

PHP:
image {
	width: 800px;
	height: 600px;
	margin-left: auto;
	margin-right: auto;
	background-repeat: no-repeat;
	background-position-y:center
}

only thing is I can’t figure out how to name the image in the JavaScript, so the CSS can “see” it and therefore control it. I’m still learning and have arrived at this requirement without knowing if it’s actually possible to do. I’d appreciate any help

Giles
(p.s I kind on need to do it this way rather than set a background image in the CSS itself)
 
>document.body.stylebackgroundImage = url()
[tt]document.body.style.backgroundImage = "url(abc.gif)";[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top