Jump to content

NEWBY NEWB NEWB problem


lAZLf

Recommended Posts

Why wont this code work:

	document.getElementById("bg").style.background= "transparent url('svid.png') fixed no-repeat 10px 30px";

 

When this code does:

	document.body.style.background = "#CCC url('svid2.png') fixed no-repeat 10px 30px";

 

 

 

 

 

Incase you're curious, here's the code i'm working with:

var winW = 630, winH = 460;

if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
}
}

if(winW > 1270) {
document.body.style.background = "#CCC url('svid2.png') fixed no-repeat 10px 30px";
document.getElementById("bg").style.background= "transparent url('svid.png') fixed no-repeat 10px 30px";
}

Link to comment
Share on other sites

Firstly is there an error in the console?

 

Secondly is it getting an object? try changing it to something simple like:

 


document.getElementById("bg").innerHTML='test';

 

if that is working then try just giving it a class instead of that inline stuff

 


<script js>

document.getElementById("bg").setAttribute("class", "myClass");

</script>

<style>

.myClass{

background: transparent url('svid.png') fixed no-repeat 10px 30px;

}

</style>

Link to comment
Share on other sites

In firebug I get this error:

uncaught exception: [Exception... "Not enough arguments"  nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)"  location: "JS frame :: http://svidler.net/ :: <TOP_LEVEL> :: line 17"  data: no]
http://svidler.net/
Line 76

 

and this error:

document.getElementById("bg") is null
http://svidler.net/
Line 76

Link to comment
Share on other sites

I got it working, aparently all I had to do was get put in the JS after both tags/objects were parsed. At first I had the code put in after the <body> tag so that part worked fine, while the #bg div was after the code, so it didn't work...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.