SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Grosseto, Italy
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change a td bgcolor when clicing a link within it.

    hi, let's say i have the following html code:

    <table border="1">
    <tr>
    <td bgcolor="#FFFFFF"><a href="#" onclick="change bg color of this cell to black">obscure</a></td>
    </table>

    when the "obscure" link is clicked the bgcolor property of the cell in which it's placed changes to #000000.

    is there a way I can do this?

    thanks

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I made this ealier for someone else as it goes.

    well here it is

    PHP Code:
    <script type="text/javascript">

      function 
    alter(what,col)
      {
        try
        {
          (
    what != null)? what.style.background col null;
        }
        catch(
    errorObject)
        {
          
    alert('what is not an obj\t error = ' errorObject.description);
        }
      }

    </script>

    <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
      <tr onMouseOver="alter(this, 'orange')" onMouseOut="alter(this, '')"> 
        <td width="20%">1</td> 
        <td width="20%">4</td> 
      </tr> 
      <tr onMouseOver="alter(this, 'orange')" onMouseOut="alter(this, '')"> 
        <td width="20%">2</td> 
        <td width="20%">5</td> 
      </tr> 
      <tr onMouseOver="alter(this, 'orange')" onMouseOut="alter(this, '')"> 
        <td width="20%">3</td> 
        <td width="20%">6</td> 
      </tr> 
    </table> 
    all you need to do it change it from onmouseover or onmouseout to onclick

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Grosseto, Italy
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    perfect! that "what.style.background" was exactly the property i was searching for.

    thank you very much

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually it's this.style.background ='orange';

    as what is referenced by 'this'


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
  •