Results 1 to 2 of 2

Thread: Background color

  1. #1
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Background color

    Hi, this code works only with ie, can anyone make it work with other browsers as well?.

    <SCRIPT language="JavaScript">
    <!--
    function bcolor(bcol,d_name)
    {
    if (document.all)
    {
    var thestyle= eval ('document.all.'+d_name+'.style');
    thestyle.backgroundColor=bcol;
    }
    }
    //-->
    </SCRIPT>


    <TABLE width="200" border="1" cellspacing="0" cellpadding="0">
    <TR>
    <TD ID="td1" style="width:50%; background-color:lightblue"
    onMouseover="bcolor('yellow','td1');"
    onMouseout="bcolor('lightblue','td1');">
    This goes to Yellow
    </TD>
    <TD ID="td2" style="width:50%; background-color:lightblue"
    onMouseover="bcolor('red','td2');"
    onMouseout="bcolor('lightblue','td2');">
    This goes to Red
    </TD>
    </TR>
    </TABLE>

    Thanks for reading!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    function bcolor(bcol,d_name) {
      if (typeof document.getElementById == "function") {
        var i, el = new Array();
        if(!(el[0] = document.getElementById(d_name))) {
          el = document.getElementsByName(d_name);
        }
        for(i=0;i<el.length;i++) el[i].style.backgroundColor = bcol;
      }
    }
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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