T
Tito
I have a html table, is possible hide and unhide some column with javascript
?
How can I do ?
?
How can I do ?
Tito said:I have a html table, is possible hide and unhide some column with
javascript ?
How can I do ?
s0lnic said:The are some options, if you're not using any JS library, and have a table
like this one:
<table id="some_table">
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
</table>
you can use the following JS code to accomplish your task:
var trs = document.getElementById('some_table').getElementsByTagName('tr');
for(var i = 0; i < trs.length; i++) {
var cell = trs.getElementsByTagName('td')[0];
if(cell.style.display == 'none'){
cell.style.display = 'block';
} else {
cell.style.display = 'none';
}
}
If you are using Prototype library
, then you can just write:
$$('td.first').invoke('toggle');
Which hide/show the first column items.
Ceterum censeo Prototype.js esse deletam.
Thomas said:According to CSS2, `table-cell' and `table-header' are the initial values
of the `display' property of `td' and `th' elements, respectively. It is
only that IE ignores that. However fortunately, current DOM
implementations allow the property value to be set to the empty string to
restore that value. Therefore:
if (cell.style.display == 'none')
{
cell.style.display = '';
}
else
{
cell.style.display = 'none';
}
-- which you should not because of its author(s) not knowing what they are
doing --
s0lnic said:That's interesting, I'm not a JS specialist and I've found this library
very, very useful. Please point out some details, what's so wrong about
Prototype?
Thomas 'PointedEars' Lahn wrote on 09 nov 2007 in comp.lang.javascript:
So you think it is already done?
RobG said:It may be an appropriate saying, even if the grammar is wrong (I'll take
your word on that).
Cato didn't live to see the total destruction of Carthage, I bet that
Thomas will not see call for total destruction come true either.
The original statement (from Marcus Porcius Cato Censorius called
"Cato the Elder") was "Ceterum censeo Carthaginem esse delendam."
which means "I also think Carthago should be destroyed." There is
nothing of a past tense in it; AFAIK, "Carthaginem delendam esse" is
accusative infinitive. Maybe I did not decline "Prototype.js"
properly (comments welcome), but I think it is understood anyway.
Nevertheless, his repeated ending his speeches in the senate this way
and thereby his repeated motion to vote on this subject eventually led
to a majority among the senators. And consequently, Carthage was
destroyed by the Romans in the Third Punic War
s0lnic said:Tito wrote:
The are some options, if you're not using any JS library, and have a table
like this one:
<table id="some_table">
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
<tr>
<td class="first">item in the first column</td>
<td>item in the second column</td>
</tr>
</table>
[cut]
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.