javascript - Hidden table row colspan fails to work - Stack Overflow

I have a table with each row having 4 td cells. It has a row hidden with one td colspan="4" i

I have a table with each row having 4 td cells. It has a row hidden with one td colspan="4" inside it.

When I show the hidden row it ignores the colspan="4" - is this because it's hidden first of all?

Is there anyway around this?

HTML

<table>
  <tr>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
  </tr>
  <tr class="hidden" id="123">
    <td colspan="4">full width</td>
  </tr>
</table>
<a href="#" onclick="showRow(); return false;">click me</a>

Javascript

function showRow(){
  el = document.getElementById('123');
  el.style.display = 'block';
}

CSS

.hidden { display:none; }

Here's a fiddle

I have a table with each row having 4 td cells. It has a row hidden with one td colspan="4" inside it.

When I show the hidden row it ignores the colspan="4" - is this because it's hidden first of all?

Is there anyway around this?

HTML

<table>
  <tr>
    <td>1</td>
    <td>1</td>
    <td>1</td>
    <td>1</td>
  </tr>
  <tr class="hidden" id="123">
    <td colspan="4">full width</td>
  </tr>
</table>
<a href="#" onclick="showRow(); return false;">click me</a>

Javascript

function showRow(){
  el = document.getElementById('123');
  el.style.display = 'block';
}

CSS

.hidden { display:none; }

Here's a fiddle

Share Improve this question asked Sep 18, 2014 at 14:48 StudioTimeStudioTime 24.1k40 gold badges128 silver badges215 bronze badges 2
  • technically a table row is not a block. – epascarello Commented Sep 18, 2014 at 14:51
  • working well for me on chrome, but try 'table-row' instead of 'block' – Hotted24 Commented Sep 18, 2014 at 14:52
Add a ment  | 

2 Answers 2

Reset to default 8

It is not a block, it is a table row

el.style.display = 'table-row';

It would be better to just remove the hidden class.

el.classList.remove("hidden");  //FYI, not all browsers support classList

In you Javascript, change

el.style.display = 'block';

to

el.style.display = 'table-row';

see jsFiddle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744988569a4604762.html

相关推荐

  • javascript - Hidden table row colspan fails to work - Stack Overflow

    I have a table with each row having 4 td cells. It has a row hidden with one td colspan="4" i

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信