Refer to a table row using a variable?

Discussion in 'Javascript' started by spam@pinkdoggy.net, Jan 14, 2006.

  1. Guest

    Hi, I hope someone can help me with what is probably quite an easy
    question!

    I need to store a string in a variable, and then use that variable to
    refer to a table row. For example:

    var row = 'row10';
    [row].style.backgroundcolor='white';

    My row is defined as:

    <tr id='row10'>

    If I use "row10.style.backgroundcolor='white' then it works, but if I
    use the variable then it doesn't. I have tried it with and without
    square brackets. What I am I doing wrong?

    Thanks
    Mark
     
    , Jan 14, 2006
    #1
    1. Advertising

  2. wrote:


    > var row = 'row10';


    > My row is defined as:
    >
    > <tr id='row10'>


    Have you never heard about
    var element = document.getElementById(row);
    then? That is the main way in the W3C DOM to access an element by the
    value of its id attribute, whether that is a tr element or just about
    any other element in a HTML document.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 14, 2006
    #2
    1. Advertising

  3. Guest

    Thank you. I had never heard of that, but it's working now.

    Cheers
    Mark
     
    , Jan 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shisncreen

    Refer to Dataset using variable

    shisncreen, Aug 10, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    398
    shisncreen
    Aug 11, 2004
  2. Anon
    Replies:
    2
    Views:
    968
    Jukka K. Korpela
    Mar 18, 2005
  3. phl
    Replies:
    1
    Views:
    4,442
    Martin Jay
    Jun 8, 2006
  4. wxl
    Replies:
    2
    Views:
    2,744
  5. D
    Replies:
    0
    Views:
    257
Loading...

Share This Page