简体   繁体   English

在CSS文件中设置height时如何获取div的高度?

[英]How to get the height of div when height is set in CSS file?

The div is been generated at run time in js file. div是在运行时在js文件中生成的。 The height of the div is defined in class. div的高度在类中定义。 Now I want to get the height of this div. 现在,我想获取此div的高度。

I have already tried :- 我已经尝试过:-

$('.maxHeight').height();
     $('.maxHeight').inner-height();
     $('.maxHeight').outer-height();
     $('.maxHeight').offset-height();
     $('.maxHeight').client-height();

Thanks 谢谢

$('.maxHeight:eq(0)').css("height");

That should work. 那应该工作。 Make sure it is selecting your actual div, and not a different one that has the same class. 确保它选择的是您实际的div,而不是具有相同类别的其他div。 Use the [0] if you have multiple instances 如果有多个实例,请使用[0]

You need to wait for the DOM-three to finish before you can run you javascript. 您需要等待DOM三完成,然后才能运行JavaScript。

Try to put you code in $(document).ready() 尝试将代码放在$(document).ready()

$(document).ready(function(){
  console.log($('.maxHeight').css("height"));
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM