View Full Version : td bgColor
09-27-2003, 08:58 PM
How can I get a TD background colour into a variable.
So, this TD.....
<td align="center" class="Mixit" bgcolor="FFFFFF">
I tried getAttribute("bgColor"), and storing it into a variable, but that didn't work.
Hope someone can help
09-27-2003, 10:17 PM
You were on the right lines with:
but to reference the element you need a unique id, as the script that I have posted shows:
09-28-2003, 12:21 AM
to reference the element you need a unique id....No, you don't, you can use DOM methods/properties to navigate the tree. Assigning and accessing an id is only one way of obtaining a specific element (object) reference.
09-28-2003, 12:31 AM
I knew someone was going to say that, although I was hoping I was wrong. OK, I realise that you can reference forms like this:
And you can also reference images in the same way along with many other elements.
However, in this case I would recommend using an id. So I'm going to rephrase:
To reference an element you CAN use a unique id.
09-28-2003, 01:20 AM
09-28-2003, 01:27 AM
Happy to help. :)
09-28-2003, 11:57 PM
OK, I realise that you can reference forms like this:
document.forms.field1.valueNot talking about DOM 0 referencing; 'navigate the tree' refers to the ability to get element objects through a variety of methods, most taking advantage of the uniformity of the DOM tree structure itself, rather than 'tagging' elements with an id. If you don't know how to do this, fine, but why not refer someone else to a good tutorial? Basic DOM is not hard to understand...
Btw, the bgColor attribute is deprecated. Use CSS background/background-color instead.
09-29-2003, 12:46 AM
OK, this is starting to piss me off a little now. Your like an Alsation who's grabbed hold of my leg and won't let go. Everything I say is wrong.
All I was getting at is that I know there are other ways of getting hold of elements and specific tags, I prefer to use id's because it's quicker.
And I know that bgcolor has been depreciated, virtually all content presentation has been, so don't have a go at me for this as well, but I don't know of any other way of changing the bgcolor of an element using JS, other than replacing the style attribute with a new one, (although I've never done that so I don't know if it will work).
Sorry if I've insulted or upset you, but I just really want you to back off a little.
09-29-2003, 06:53 PM
OK, this is starting to piss me off a little now.Solution: don't post here anymore.
If you can't take comments on your offerings, just find a nice (beginners) board where they think you're a genius.
This one has been here for a bit, gotten along fine without you, thanks anyhow.
Happy to help. :)
09-30-2003, 11:41 AM
I just want to help people, whenever I can, without someone picking up on every little miskate that I make. I don't really care how anyone thinks of me so long as I don't find out about it, (unless it's good).
I don't mind people correcting me, and as for being around for a while, it doesn't look like you've been here since the beginning either.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.