javascript - Can't change height of table cell - Stack Overflow

I'm trying to dynamically change the height of a cell than contains a div.Now i can change the h

I'm trying to dynamically change the height of a cell than contains a div. Now i can change the height of the div, just fine, but when I try the cell, it just doesn't work, yet I get no errors. Any Ideas on why this doesn't work?

if( df0.checkbox1.checked)
{
    document.getElementById('layerOne').style.visibility = 'visible';
    document.getElementById('layerOne').style.height = 125;
    document.getElementById('eftcell').height = '125px'
}
else
{
    document.getElementById('layerOne').style.visibility = 'hidden';
    document.getElementById('layerOne').style.height = 1; 
    document.getElementById('eftcell').height = '1px'
}

I'm trying to dynamically change the height of a cell than contains a div. Now i can change the height of the div, just fine, but when I try the cell, it just doesn't work, yet I get no errors. Any Ideas on why this doesn't work?

if( df0.checkbox1.checked)
{
    document.getElementById('layerOne').style.visibility = 'visible';
    document.getElementById('layerOne').style.height = 125;
    document.getElementById('eftcell').height = '125px'
}
else
{
    document.getElementById('layerOne').style.visibility = 'hidden';
    document.getElementById('layerOne').style.height = 1; 
    document.getElementById('eftcell').height = '1px'
}
Share edited Jun 9, 2011 at 15:25 SubmittedDenied 9577 silver badges13 bronze badges asked Jun 9, 2011 at 15:05 LimeyLimey 2,7826 gold badges38 silver badges69 bronze badges 4
  • It's "height".. and that indentation style is horrid! – Lightness Races in Orbit Commented Jun 9, 2011 at 15:10
  • Not sure what you are trying to say, I am using "height" – Limey Commented Jun 9, 2011 at 15:17
  • Not originally in the text and title. – Lightness Races in Orbit Commented Jun 9, 2011 at 15:30
  • but my code was good though (at least in the spelling of height) – Limey Commented Jun 9, 2011 at 15:49
Add a ment  | 

3 Answers 3

Reset to default 3

Use the "px" unit when changing style.property:

document.getElementById('layerOne').style.height = "125px";
document.getElementById('eftcell').height = 125;

I did a bit of testing in FireFox 4 (via Firebug), it seems to work for me. Here are some things to look for:

  • Try using just the number 125 for height, rather than the string '125px'
  • Make sure that the element with id="eftcell" is the <td> element, not its parent <tr>
  • Look into patibility issues between browsers, maybe your browser doesn't allow a height attribute on <td>?

Needs px and to be in a string. Also HTML5 doesn't support javascript height on TD cells.

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

相关推荐

  • javascript - Can&#39;t change height of table cell - Stack Overflow

    I'm trying to dynamically change the height of a cell than contains a div.Now i can change the h

    2小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信