Set bgcolor of a newly added table row?

Discussion in 'Javascript' started by Martin, Nov 19, 2004.

  1. Martin

    Martin Guest

    I'm using the following function to insert a new row in a table. This
    works fine - no problems. But, I would like to also set the background
    color of the new row and I can't figure out how to do it.

    I tried adding: Y.bgcolor='green'; after the Y.innerHTML = Msg1;
    but that didn't work.

    I tried adding:
    at the end of the funtion but that didn't work either.

    Can someone give me a clue here?


    function insRow(Msg1,Msg2)
    var x=document.getElementById('TableX').insertRow(1);
    var Y = x.insertCell(0);
    var Z = x.insertCell(1);
    Y.innerHTML = Msg1;
    Z.innerHTML = Msg2;
    Martin, Nov 19, 2004
    1. Advertisements

  2. Martin

    kaeli Guest

    That would be b/c the property name is Y.bgColor. Case-sensitive.
    Or you can do That one works for more elements than
    bgColor does, I think.

    kaeli, Nov 19, 2004
    1. Advertisements

  3. Martin

    Rob B Guest


    The CSS 'background' property is a catch-all for every
    background-related attribute; the parser knows which is which by its
    data format. Don't use 'bgColor', it's deprecated.

    Rob B, Nov 19, 2004
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.