Hide table/row

J

John M

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!
 
M

Martin Honnen

John said:
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>
 
L

Louise Woodward

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 said:
John said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top