使用jquery查找类的高度

时间:2021-09-28 04:17:33

I have many child divs with same class name. Out of all the divs only one div will appear based on the users selection and other divs will be set to display: none;.

我有很多具有相同类名的子div。在所有div中,只有一个div将根据用户选择显示,其他div将设置为display:none;。

How can I find out the height of the class which is currently in display: block? I tried using ids but it wasn't possible since I have many divs. Thanks in advance.

如何找出当前显示的类的高度:块?我尝试使用id但是因为我有很多div而不可能。提前致谢。

4 个解决方案

#1


2  

Try with :visible:

试试:可见:

var height = $('.class:visible').css('height'); // will give you css height
var height = $('.class:visible').height(); // will give you calculated height

#2


0  

Use the common class to select all the div elements, then use the :visible selector to access the one which is currently displayed. From there you can access the height() property. Something like this:

使用公共类选择所有div元素,然后使用:visible选择器访问当前显示的那个。从那里你可以访问height()属性。像这样的东西:

var height = $('.elements:visible').height();

#3


0  

Let us say your elements has classname childdivs, you can use :visible selector to target visible element:

让我们说你的元素有classname childdivs,你可以使用:visible selector来定位可见元素:

 $('.childdivs:visible').height()

#4


0  

Mutiple Ways

  1. $(".highlight:visible").height();

  2. $('.highlight[style*="block"]').height();

#1


2  

Try with :visible:

试试:可见:

var height = $('.class:visible').css('height'); // will give you css height
var height = $('.class:visible').height(); // will give you calculated height

#2


0  

Use the common class to select all the div elements, then use the :visible selector to access the one which is currently displayed. From there you can access the height() property. Something like this:

使用公共类选择所有div元素,然后使用:visible选择器访问当前显示的那个。从那里你可以访问height()属性。像这样的东西:

var height = $('.elements:visible').height();

#3


0  

Let us say your elements has classname childdivs, you can use :visible selector to target visible element:

让我们说你的元素有classname childdivs,你可以使用:visible selector来定位可见元素:

 $('.childdivs:visible').height()

#4


0  

Mutiple Ways

  1. $(".highlight:visible").height();

  2. $('.highlight[style*="block"]').height();