/    Sign up×
Community /Pin to ProfileBookmark

Okay. I’m trying to dynamically modify the pages CSS styling, and change the background image. Here’s what I was told to try.
<body id=”id_name”>

and the script…

document.getElementById(“id_name”).style.backgroundImage=”name.jpg”;
or,
document.body.style.backgroundImage=”name.jpg”;

Neither one works. How can I modify the background image with Javascript through changing the style?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 11.2006 — Try using an absolute URL.
Copy linkTweet thisAlerts:
@mjdamatoNov 11.2006 — You need to do it like this:

document.body.style.backgroundImage = "url(name.jpg)"
Copy linkTweet thisAlerts:
@comingbackdownauthorNov 11.2006 — You need to do it like this:

document.body.style.backgroundImage = "url(name.jpg)"[/QUOTE]


Uh... Now I'm even more confused... ?
Copy linkTweet thisAlerts:
@mjdamatoNov 13.2006 — When specifying a file in CSS it needs to be set using that format. The "url" can be a proper url to an external file or a relative url to the file within the current directory.

http://www.w3schools.com/css/pr_background-image.asp
×

Success!

Help @comingbackdown spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...