最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - clientHeight in FireFox - Stack Overflow

programmeradmin5浏览0评论

I have a table in HTML code.

I need to get height of that table using JavaScript, so

alert(document.getElementById('myTable').clientHeight);

returns a correct value in IE, but always returns 0 in FF.

How can I get the height of the table in Firefox?

Thanks!

I have a table in HTML code.

I need to get height of that table using JavaScript, so

alert(document.getElementById('myTable').clientHeight);

returns a correct value in IE, but always returns 0 in FF.

How can I get the height of the table in Firefox?

Thanks!

Share Improve this question edited Feb 18, 2011 at 13:47 Robert Koritnik 105k56 gold badges286 silver badges413 bronze badges asked Feb 18, 2011 at 13:39 ihorkoihorko 6,95526 gold badges80 silver badges123 bronze badges 2
  • Try offsetHeight or scrollHeight ... – Šime Vidas Commented Feb 18, 2011 at 13:46
  • 1 Just tried, offsetHeight returns 0 and scrollHeight also retorns 0 in FF :( – ihorko Commented Feb 18, 2011 at 13:49
Add a ment  | 

4 Answers 4

Reset to default 5

MDC says:

clientHeight is a non-standard, HTML-specific property introduced in the Internet Explorer object model.

In Firefox, the offsetHeight property contains the current pixel height of an element, so you can use something like:

var theHeight = element.clientHeight || element.offsetHeight;

Did you tried offsetHeight? See http://www.quirksmode/dom/w3c_cssom.html

clientHeight works in my Firefox: http://jsfiddle/sZ9eg/

Maybe eone can correct me here, but if you want to get the height of a specific element then why not just use

EDIT: this only works if the element has inline styles and a defined height

document.getElementById('myReputation').style.height;
发布评论

评论列表(0)

  1. 暂无评论