lAZLf Posted February 9, 2010 Share Posted February 9, 2010 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"; } Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 "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)... Quote Link to comment Share on other sites More sharing options...
lAZLf Posted February 9, 2010 Author Share Posted February 9, 2010 I know, and I do have a div with an ID set to "bg". But it still doesn't work. Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 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> Quote Link to comment Share on other sites More sharing options...
lAZLf Posted February 9, 2010 Author Share Posted February 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
lAZLf Posted February 9, 2010 Author Share Posted February 9, 2010 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.