SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    changing td background color

    I am using a script that changes id.style.background on a td.

    http://www.unpossible.cc

    It works the way it should in mac and pc ie. In ns however, the color does not change back the first time you mouse out. Does anyone know how to remedy this?
    TIA

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would suggest posting the script if it's not too long.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Fort Lauderdale
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the javascript. get_obj() returns a reference to the object depending on which browser. The main concern would be with highlight() and unhighlight()
    PHP Code:
      function get_obj(objis_style) {
                    if (
    is_style) {
                        if (
    document.getElementById) {
                            return 
    document.getElementById(obj).style;
                        } else if (
    document.all) {
                            return 
    document.all[obj].style;
                        } else if (
    document.layers) {
                            return 
    document.layers[obj];
                        }
                    } else {
                        if (
    document.getElementById) {
                            return 
    document.getElementById(obj);
                        } else if (
    document.all) {
                            return 
    document.all[obj];
                        } else if (
    document.layers) {
                            return 
    document.layers[obj];
                        }
                    }
                }
                function 
    highlight(obj) {
                    
    get_obj(obj1).background "#6D7887";
                }
                function 
    unhighlight(obj) {
                    
    get_obj(obj1).background "#4d555f";
                } 
    The HTML portion is this:
    PHP Code:
    a onMouseOver="highlight('TD_ID');" onMouseOut="unhighlight('TD_ID');" 

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my go. Seems to work OK in Mozilla and IE on both PC and Mac.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <script language="javascript">
    
    function changeElementColor(obj, color) {
       obj.style.backgroundColor = color;
    }
    
    </script>
    </HEAD>
    
    <BODY>
    <table>
      <tr>
        <td onmouseover="changeElementColor(this, 'blue')" onmouseout="changeElementColor(this, 'white')">foo</td>
        <td onmouseover="changeElementColor(this, 'blue')" onmouseout="changeElementColor(this, 'white')">bar</td>
      </tr>
    </table>
    </BODY>
    </HTML>


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
  •