It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

change TD background using jscript

change TD background using jscript

Postby lvermeersch on Thu Sep 15, 2005 8:39 am

i want to change the tablecell background using a script
i am new to getElementByID
i tried something like

My table cell TD id is Cell1
Now i want to change the background image
document.getElementByID('Cell1').background= "backG.jpg";
or
document.getElementByID('Cell1').background= url(backG.jpg);

This doesn't seem to work
although i can get the current imagename displayed with
alert(document.getElementByID('Cell1').background);
What am i doing wrong
lvermeersch
 
Posts: 13
Joined: Thu Aug 25, 2005 9:30 am

Postby lvermeersch on Thu Sep 15, 2005 10:56 am

I can add my table code to make things more clear.

<table width=100% >
<tr> <td width=170px id="MenuafbSM1" background="Clown button.jpg">
<span id=MenutekstSM1 language="javascript" onmouseover="alert(document.getElementById('MenuafbSM1').background);" onclick="document.getElementById('ID_Scherm').contentWindow.document.location='Mijn vrienden_GEN.htm'"> Mijn&nbsp;vrienden</span>
</td>
</tr></table>

I now have used
onmouseover="alert(document.getElementById('MenuafbSM1').background);"
this gives Clown button.jpg as result but notice only the second time i hover over the span, the first time i get Undefined as a result.
Probably this causes to prevent the background cellchange
and i want to use
onmouseover="document.getElementById('MenuafbSM1').background='Clown button2.jpg';"
to change the cell background when hovering over span but this does not work.
(Don't bother about the table span construction, this has to be this way because it is generated code and has allso other functions.)
lvermeersch
 
Posts: 13
Joined: Thu Aug 25, 2005 9:30 am


Who is online

Users browsing this forum: No registered users and 3 guests