calling to obj\elemet

Discussion in 'JavaScript' started by yuri1992, Mar 16, 2008.

  1. #1
    in the html file i have this code:
    how i change the color of the td ?

    HTML Code:
    <table width=600 id=games>
    <td id=2_$id style='background-color:'
    onclick='bet_detils($teamav, $id, $x2);'>
    <B>
    <font face=Arial size=1 color=bb2618>
    <div align=right><a href='javascript: void(0);'>$teamav</a></td>
    in the java i have this....
    function bet_detils(yahs,idz,chose)
    {
    var idfinish=chose+'_'+idz;
    idfinish.style.backgroundcolor=blue;
    }

    how i call to the this td from a function
     
    yuri1992, Mar 16, 2008 IP
  2. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    HTML:

    <td id='someID'>blah blah blah</td>

    <a href="javascript:void(0);" onclick="changeColor('someID')">Click to change color</a>

    JAVASCRIPT:

    function changeColor(id) {

    document.getElementById(id).style.backgroundColor = '#000AFF';

    }


    Remember, most CSS attributes are represented as properties in the Style object. For non hyphenated attributes, the property is identical, while for hyphenated attributes, drop the hyphen and capitalize the first letter following it. For instance, to manipulate the "background-color" property of CSS via the DOM, the syntax would look something like:

    document.getElementById("ID").style.backgroundColor="white";

    CSS: background-color
    Javascript: backgroundColor
     
    GreatMetro, Mar 17, 2008 IP