Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: td bgColor

  1. #1
    New Coder
    Join Date
    Dec 2002
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    td bgColor

    Hi,

    How can I get a TD background colour into a variable.

    So, this TD.....

    <td align="center" class="Mixit" bgcolor="FFFFFF">

    with javascript how can i get that bgcolor into a variable to use later in a script.

    I tried getAttribute("bgColor"), and storing it into a variable, but that didn't work.

    Hope someone can help

    Thanks

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You were on the right lines with:

    getAttribute("bgColor")

    but to reference the element you need a unique id, as the script that I have posted shows:
    Attached Files Attached Files
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    http://www.scottandrew.com/weblog/articles/dom_1
    &nbsp;........ another wild guess ........

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    document.forms[0].field1.value

    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.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #5
    New Coder
    Join Date
    Dec 2002
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Guys,


  • #6
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Happy to help.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #7
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, I realise that you can reference forms like this:

    document.forms[0].field1.value
    Not 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.
    &nbsp;........ another wild guess ........

  • #8
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150

  • #9
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    &nbsp;........ another wild guess ........

  • #10
    Regular Coder
    Join Date
    Aug 2003
    Location
    Loughborough University
    Posts
    427
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    AMD Athlon "Barton" XP 3200+ (11*200.5MHz = 2.2GHz)
    BFG GeForce 6800 Ultra OC 256Mb
    3 * Kingston 256Mb PC3200 DDR400
    Seagate Barracuda 120Gb Ultra ATA-100 and Seagate Barracuda 160Gb, SATA-150


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •