Hide table/row

Discussion in 'Javascript' started by John M, Oct 16, 2003.

  1. John M

    John M Guest

    I want to hide the first row in my table and if a user click on a show
    button than show it. If it is visible than user can hide it with click a
    hide button.
    In default I hide it with:

    <tr id="ds" style="display:none">

    but how can I make it visible or hide it dynamicaly?

    Is it possible to do it not with TR but with TABLE?

    Thanks!
     
    John M, Oct 16, 2003
    #1
    1. Advertising

  2. John M wrote:

    > I want to hide the first row in my table and if a user click on a show
    > button than show it. If it is visible than user can hide it with click a
    > hide button.
    > In default I hide it with:
    >
    > <tr id="ds" style="display:none">
    >
    > but how can I make it visible or hide it dynamicaly?


    function hideElement (elementId) {
    var element;
    if (document.all)
    element = document.all[elementId];
    else if (document.getElementById)
    element = document.getElementById(elementId);
    if (element && element.style)
    element.style.display = 'none';
    }
    function showElement (elementId) {
    var element;
    if (document.all)
    element = document.all[elementId];
    else if (document.getElementById)
    element = document.getElementById(elementId);
    if (element && element.style)
    element.style.display = '';
    }

    Now you can call
    showElement('ds');
    to show the table row.
    However as not all browsers support JavaScript and even some of those
    that do don't support toggling style.display it is better if you don't use
    <tr id="ds" style="display:none">
    to hide the row but rather do it with script e.g.
    <table>
    <tr id="ds">
    <td>...</td>
    ...
    </tr>
    ...
    </table>
    <script type="text/javascript">
    hideElement('ds');
    </script>



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 16, 2003
    #2
    1. Advertising

  3. Can you use style.display with labels too or not as I am trying it and
    I keep getting label is null but if I use an input textbox then it works

    Thanks

    "Martin Honnen" <> wrote in message
    news:3f8ec45c$...
    >
    >
    > John M wrote:
    >
    > > I want to hide the first row in my table and if a user click on a show
    > > button than show it. If it is visible than user can hide it with click a
    > > hide button.
    > > In default I hide it with:
    > >
    > > <tr id="ds" style="display:none">
    > >
    > > but how can I make it visible or hide it dynamicaly?

    >
    > function hideElement (elementId) {
    > var element;
    > if (document.all)
    > element = document.all[elementId];
    > else if (document.getElementById)
    > element = document.getElementById(elementId);
    > if (element && element.style)
    > element.style.display = 'none';
    > }
    > function showElement (elementId) {
    > var element;
    > if (document.all)
    > element = document.all[elementId];
    > else if (document.getElementById)
    > element = document.getElementById(elementId);
    > if (element && element.style)
    > element.style.display = '';
    > }
    >
    > Now you can call
    > showElement('ds');
    > to show the table row.
    > However as not all browsers support JavaScript and even some of those
    > that do don't support toggling style.display it is better if you don't use
    > <tr id="ds" style="display:none">
    > to hide the row but rather do it with script e.g.
    > <table>
    > <tr id="ds">
    > <td>...</td>
    > ...
    > </tr>
    > ...
    > </table>
    > <script type="text/javascript">
    > hideElement('ds');
    > </script>
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    >
     
    Louise Woodward, Oct 17, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA
    Replies:
    1
    Views:
    4,032
  2. Utter Newbie

    Hide Table Row In Repeater?

    Utter Newbie, Aug 25, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    8,140
    bartekm
    Mar 3, 2011
  3. phl
    Replies:
    1
    Views:
    4,386
    Martin Jay
    Jun 8, 2006
  4. D
    Replies:
    0
    Views:
    239
  5. UJ
    Replies:
    1
    Views:
    139
Loading...

Share This Page