PDA

View Full Version : catch bgcolor from a script


usban
03-24-2004, 10:58 PM
I want to be able to take the background-color of a determined cell

<table id="fondo" width="25px" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#454545">
<tr>
<td>&nbsp;</td>
</tr>
</table>


the when i press a button i want to be able to catch tha #454545, i get it in iexplorer but i cannot do it with netscape.

function muestra() {

var id2 = "fondo";

var obj2 = document.getElementById ? document.getElementById(id2) : document.all ? document.all(id2) : null;

alert(obj2.style.bgcolor);

}

I've tried qith bgcolor, background, color, ... but i only get "undefined" or even something like "4545px 50%" wich has no sense for me :confused:

usban
03-24-2004, 11:19 PM
ok.

Sorry everyone, but first i must have looked at Google.
the solution is call obj2.bgColor

:thumbsup:

shlagish
03-25-2004, 01:22 AM
or: obj2.style.backgroundColor
I think would have worked

glenngv
03-25-2004, 04:39 AM
That would work if usban used CSS to format the table instead of the old attributes bgcolor, border, etc.

<table id="fondo" style="background-color:#454545; border:none; width:25px">

Kor
03-25-2004, 09:40 AM
That is not so simple.

obj.style.attribute will work only if the style are set up inside the tag with style="". What about global and external CSS?

For this, see

http://www.javascriptkit.com/dhtmltutors/dhtmlcascade.shtml