Closed Thread Icon

Preserved Topic: Addressing Table Cell Background Image Pages that link to <a href="https://ozoneasylum.com/backlink?for=18562" title="Pages that link to Preserved Topic: Addressing Table Cell Background Image" rel="nofollow" >Preserved Topic: Addressing Table Cell Background Image\

 
Author Thread
Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 09-24-2001 20:45

So, I'm using a very simple function to change the background image of a particular table cell for one particular page on my site. The table cell uses the ID "contentCell" and I use an onLoad event in the BODY to run a simple function (below). Naturally, it's easy to target the cell's background in IE, but I can't figure out how to target it in NN.

function changeBG() {
contentCell.background = "background.gif" }

Can anyone help?


mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-24-2001 21:28

In NN4 you can't change TD element's background dynamically (only layers can change background image in NN4). Changing background image on TD element will work in Opera, IE and Mozilla... Use the following code:

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;

// Written by mr.maX, http://www.max.co.yu/

function setTDbgImage(layer, src) {
    if (document.getElementById) {
        document.getElementById(layer).style.backgroundImage = "url('" + src + "')";
    } else
    if (document.all) {
        document.all[layer].style.backgroundImage = "url('" + src + "')";
    }
}

// -->
</SCRIPT>

<BODY ONLOAD="setTDbgImage('contentCell', 'newImage.gi')">

BTW Although your code works in IE, it is not written correctly...



[This message has been edited by mr.maX (edited 09-25-2001).]

Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 09-25-2001 07:13

Cool, thanks, Max. I have a couple questions, though.

1. Should document.all[name] be document.all[layer]?

2. Both methods (document.getElementById and document.all) seem to work in IE (if I make the change above, that is); which is necessary for Opera and Mozilla?

3. Do I need to use both methods to replace a straight image (not a background)?

Thanks again!




[This message has been edited by Wes (edited 09-25-2001).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-25-2001 07:46

document.all is an IE construct

document.getElementById will work in mozilla I'm assuming opera as well if it's following the dom (that's where this comes from)

images in all are objects of their own. imageName.src should work at this point in all browsers.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-25-2001 14:36

IE came up with doc.all before the getElementById standard was created. So IE 4 supports only doc.all, IE 5 and 6 supports doc.all *and* getElementById. Standard compliant browsers (mozilla for instance) support only getElementById.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 09-25-2001 19:53

Wes, yes, it should be document.all[layer] (I made small typing error). Also, you should use complete function (exactly as I wrote it), if you want to make your page work in Opera, IE and Mozilla...

BTW Regarding Opera, when it's running in MSIE compatibility mode, document.all is availabe, otherwise document.getElementById() is used...

Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 09-25-2001 22:27

Wonderful! I believe all my questions are answered.

Thanks, all!


« BackwardsOnwards »

Show Forum Drop Down Menu