Author Topic: NEWBY NEWB NEWB problem  (Read 413 times)

0 Members and 1 Guest are viewing this topic.

Offline lAZLfTopic starter

  • Enthusiast
  • Posts: 89
    • View Profile
NEWBY NEWB NEWB problem
« on: February 09, 2010, 05:01:34 PM »
Why wont this code work:
Code: [Select]
document.getElementById("bg").style.background= "transparent url('svid.png') fixed no-repeat 10px 30px";

When this code does:
Code: [Select]
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:
Code: [Select]
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";
}

Offline seventheyejosh

  • Devotee
  • Posts: 633
  • i see what you did there...
    • View Profile
    • Net Worth Pro
Re: NEWBY NEWB NEWB problem
« Reply #1 on: February 09, 2010, 05:22:58 PM »
"bg" is referring to an element with an id of "bg" like... <div id="bg"> if it's like the body you want it is something like getElementById(body)...
My first iPhone app is out! Check it out -> http://networthproapp.com

Offline lAZLfTopic starter

  • Enthusiast
  • Posts: 89
    • View Profile
Re: NEWBY NEWB NEWB problem
« Reply #2 on: February 09, 2010, 06:27:21 PM »
I know, and I do have a div with an ID set to "bg".

But it still doesn't work.

Offline seventheyejosh

  • Devotee
  • Posts: 633
  • i see what you did there...
    • View Profile
    • Net Worth Pro
Re: NEWBY NEWB NEWB problem
« Reply #3 on: February 09, 2010, 06:44:13 PM »
Firstly is there an error in the console?

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

Code: [Select]

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


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

Code: [Select]

<script js>

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

</script>

<style>

.myClass{

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

}

</style>

My first iPhone app is out! Check it out -> http://networthproapp.com

Offline lAZLfTopic starter

  • Enthusiast
  • Posts: 89
    • View Profile
Re: NEWBY NEWB NEWB problem
« Reply #4 on: February 09, 2010, 06:47:14 PM »
In firebug I get this error:
Code: [Select]
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:
Code: [Select]
document.getElementById("bg") is null
http://svidler.net/
Line 76

Offline lAZLfTopic starter

  • Enthusiast
  • Posts: 89
    • View Profile
Re: NEWBY NEWB NEWB problem
« Reply #5 on: February 09, 2010, 06:56:22 PM »
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...