Click to See Complete Forum and Search --> : How to call dymanically an id (span, td, etc) ?


Bougli
06-12-2003, 04:11 AM
Hi.
I'm french then my problem is not easy to explain (for me).

I've a some td in a table that i want to change bgcolor.
then i've named my td as :

<td id="td1" align.....
<td id="td2" align.....
etc

then i can do :
td_1.bgColor='f0f0f0';

but for some reason i need to call dynamically the name of the td. i've tried this :

my_number = comes from a function will be 1,2, etc;
["td" + my_number].bgColor='ffffff';

and this doesn't work. i've put "document." before but nothing better.

do you know the correct syntax for this ? thanks

Gollum
06-12-2003, 04:18 AM
try

document.getElementById("td" + my_number).bgColor

Bougli
06-12-2003, 04:34 AM
this seems to work !

a BIG thanks !

Khalid Ali
06-12-2003, 06:13 AM
Originally posted by Gollum
try

document.getElementById("td" + my_number).bgColor

If the above works then it must only work in IE
it should be

document.getElementById("td" + my_number).style.backgroundColor="green"

Reason being that TD does not have bgColor attribute in any future versions of it.(it will only work in transitional DTDs)