[Javascript] Hide show a TD

Chris T christ at saeweb.com
Mon Jun 21 11:11:43 CDT 2004


>> function showSub(id){
>>        alert( document.getElementById(id).style.display) // output "none"
>>        document.getElementById(id).style.display == 'inline';
>>        alert( document.getElementById(id).style.display) // output
>> "none" also !!!
>>
>>       // I do not even tried to debug the rest of the function
>>       // but I bet it won't change the dislplay attribute also.
>>
>>        for (i=1;i<5; i++){
>>                if (i!= id){
>>                        document.getElementById(i).style.display ==
'none';
>>                }
>>        }
>> }



I count it being used no less than 4 times here. Sure in the loop it's only
setting one particular property, but if you're going to ever expand this to
do more, you will want to set the instance to a variable so you can
manipulate properties easier.

Good technique is not always the most efficient in short scripts, but if you
emphasize it all the time, it will come natural to you and will help out
greatly in larger projects.

Chris Tifer

----- Original Message ----- 
From: "Mike Dougherty" <mdougherty at pbp.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Monday, June 21, 2004 12:04 PM
Subject: Re: [Javascript] Hide show a TD


Why set a variable for an object you are only going to use once inside a
loop?


Are these elements inside a container object?  If so, you could use for(itm
in collection){}
syntax - although performance is probably going to be comparable for such a
small number of
elements.

On Mon, 21 Jun 2004 12:03:04 -0400
  "Chris T" <christ at saeweb.com> wrote:
>One more thing: Just to make this more readable you should try to set your
>instance of that object to a variable:
>
>var objEl = document.getElementById(id)
>objEl.style.display = "whatever you want"
>
>
>>        for (i=1;i<5; i++){
>>                if (i!= id){
>>                        document.getElementById(i).style.display ==
'none';
>>                }
>>        }
>
>And that's some funky code logic-wise. Are your ID's numbers?
>
>Chris Tifer
>
>----- Original Message ----- 
>From: "Marcelo Wolfgang" <grillo at gmail.com>
>To: <javascript at latech.edu>
>Sent: Monday, June 21, 2004 11:16 AM
>Subject: [Javascript] Hide show a TD
>
>
>> Hi list,
>>
>> I'm trying to come with a script to hide show layers based on their
>> id, everything looks fine, except it ain't changing the style of the
>> TD :(
>>
>> Here's my js code :
>>
>> <script>
>> function showSub(id){
>>        alert( document.getElementById(id).style.display) // output "none"
>>        document.getElementById(id).style.display == 'inline';
>>        alert( document.getElementById(id).style.display) // output
>> "none" also !!!
>>
>>       // I do not even tried to debug the rest of the function
>>       // but I bet it won't change the dislplay attribute also.
>>
>>        for (i=1;i<5; i++){
>>                if (i!= id){
>>                        document.getElementById(i).style.display ==
'none';
>>                }
>>        }
>> }
>> </script>
>>
>> and here's the TD :
>>
>> <tr>
>>        <td><a href="javascript:showSub(1)"><img
>> src="images/menu_btProducts_off.gif" width="134" height="23"
>> border="0"></a></td>
>> </tr>
>> <tr>
>>        <td id="1" style="display:none">
>>                <table border="0" cellpadding="0" cellspacing="0">
>>                <tr>
>>                        <td><img src="images/menu_btShopMedia_off.gif"
>> width="134"
>> height="22" border="0"></td>
>>                </tr>
>>                <tr>
>>                        <td bgcolor="#20214F"><img src="images/dot.gif"
>width="1"
>> height="1" border="0"></td>
>>                </tr>
>>                </table>
>>        </td>
>> </tr>
>>
>> Can anyone help me ?
>>
>> TIA
>> Grillo
>> _______________________________________________
>> Javascript mailing list
>> Javascript at LaTech.edu
>> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list