Fluence
07-05-2006, 07:39 PM
Question:
Is there a way to set one div's background or backgroundImage to the value of another div's background or backgroundImage?
Basically, what I'm trying to do is the following, on mouse click:
div0.background = div1.background
I have it working while using
div0.background = 'url(/background/of/div1.jpg)'
but this is causing me problems in another area (described below)
I notice that alert(div0.style.background) returns blank, and this must be why I can't do div0.background=div1.background... but, is there a way to do this? Is my syntax just off?
The following is the actual code I'm using. The line I'm trying to change is defBg.style.background = { 'url...
function rowEvents (elem, prop) {
var y = elem.id.charAt (6);
var z = getObj ('bg' + y + '');
switch (prop) {
case "visible": z.obj.className = 'visible bg'; break;
case "hidden": z.obj.className = 'hidden bg'; break;
case "defaultBg": { var defBg = getObj ('bg0');
defBg.style.background = 'url(/themes/ASIH/Images/FishRep/Large-Footer' + y + '.jpg) center no-repeat'; break; }
default: alert (elem.id); }}
#bg0 is the default background
"elem" is the background I'm trying to set as the default background (#bg0), basically document.getElementById('bg' #) where # is between 1-9
"prop" 'visible' and 'hidden' work fine, as does 'default', but I need it to work in a different manner.
The divs are set up with id of bg#s 1-9, as follows, with #bg0 being the default background:
#bg0, #bg5 { background: url(Images/desert.jpg) center no-repeat; }
#bg1 { background: url(Images/FishRep/Large-Footer1.jpg) center no-repeat;
#bg2 { background: url(Images/FishRep/Large-Footer2.jpg) center no-repeat;
#bg3 { .... etc...
so, y returns the number of the above. This has to be redeclared as when the function runs, (elem) is no longer the same
Thus, what I'm trying to do is have the default background equal the background of the other div, ie:
defBg.style.background = bg#.style.background
where # is the current value of y
The problem I've run into stems from #bg0 and #bg5, which are different urls depending on the screen resolution, (which is declared in a different stylesheet).
I checked alert(element.style.background), and it returns blank, which makes me think that element.style.background isn't the right syntax, or... .something...
So, again, is there anyway to set one div's (#bg0) background equal to that of another div (#bgy)?
Thanks in advance.
Is there a way to set one div's background or backgroundImage to the value of another div's background or backgroundImage?
Basically, what I'm trying to do is the following, on mouse click:
div0.background = div1.background
I have it working while using
div0.background = 'url(/background/of/div1.jpg)'
but this is causing me problems in another area (described below)
I notice that alert(div0.style.background) returns blank, and this must be why I can't do div0.background=div1.background... but, is there a way to do this? Is my syntax just off?
The following is the actual code I'm using. The line I'm trying to change is defBg.style.background = { 'url...
function rowEvents (elem, prop) {
var y = elem.id.charAt (6);
var z = getObj ('bg' + y + '');
switch (prop) {
case "visible": z.obj.className = 'visible bg'; break;
case "hidden": z.obj.className = 'hidden bg'; break;
case "defaultBg": { var defBg = getObj ('bg0');
defBg.style.background = 'url(/themes/ASIH/Images/FishRep/Large-Footer' + y + '.jpg) center no-repeat'; break; }
default: alert (elem.id); }}
#bg0 is the default background
"elem" is the background I'm trying to set as the default background (#bg0), basically document.getElementById('bg' #) where # is between 1-9
"prop" 'visible' and 'hidden' work fine, as does 'default', but I need it to work in a different manner.
The divs are set up with id of bg#s 1-9, as follows, with #bg0 being the default background:
#bg0, #bg5 { background: url(Images/desert.jpg) center no-repeat; }
#bg1 { background: url(Images/FishRep/Large-Footer1.jpg) center no-repeat;
#bg2 { background: url(Images/FishRep/Large-Footer2.jpg) center no-repeat;
#bg3 { .... etc...
so, y returns the number of the above. This has to be redeclared as when the function runs, (elem) is no longer the same
Thus, what I'm trying to do is have the default background equal the background of the other div, ie:
defBg.style.background = bg#.style.background
where # is the current value of y
The problem I've run into stems from #bg0 and #bg5, which are different urls depending on the screen resolution, (which is declared in a different stylesheet).
I checked alert(element.style.background), and it returns blank, which makes me think that element.style.background isn't the right syntax, or... .something...
So, again, is there anyway to set one div's (#bg0) background equal to that of another div (#bgy)?
Thanks in advance.