[Javascript] hiding single td cells

Michael Borchers list at tridemail.de
Tue Apr 25 07:45:12 CDT 2006


> First switch to using class. Then change the value to something
> allowed. Then run your document through the W3C Markup Validation
> Service. Then use getElementsByTag name to find all the table data
> cells. Then loop through them checking the className property. Alter
> the style.display property of those that match.

ok, i got it so far:
<table width="40%" cellpadding="0" cellspacing="2" border="1">
  <tr>
 <td>A</td>
 <td class="conversionsDetails" style="display:table-cell">B</td>
 <td class="conversionsDetails" style="display:table-cell">C</td>
...

the function:
{
 var conversionsDetails   = document.getElementsByTagName("td");
 var conversionsDetailsLength = conversionsDetails.length;
 
 for(tc=0;tc<conversionsDetailsLength;tc++)
 {
  if(conversionsDetails[tc].className == "conversionsDetails")
  {
   if(conversionsDetails[tc].style.display == '')
   {
    conversionsDetails[tc].style.display = "none";
   }
   else
   {
    if(conversionsDetails[tc].style.display == 'table-cell')
    {
     conversionsDetails[tc].style.display = "none";
    }
    else
    {
     conversionsDetails[tc].style.display = "table-cell";
    }
   }
  }
 }
}

it works fine when wanting them to disappear but
i can't bring'em back:( the display property seems to be missing, but why?



More information about the Javascript mailing list