[英]how to get width of ul on the base of class jquery?
How can get width of <ul>
on the class name as class name will be unique for each <ul>
. 如何获得类名上
<ul>
宽度,因为每个<ul>
类名都是唯一的。
I don't want to select by id
, but rather by class
so it can be reused, 我不想按
id
选择,而是按class
选择,以便可以重用,
My <ul>
html is: 我的
<ul>
html是:
<ul id="cat-sec-bar" class="RestaurantssubTypeDivClass" style="display: block;">
//some code here
</ul>
I am trying with this: 我正在尝试:
var divWidth = $(".RestaurantssubTypeDivClass").width();
//Getting 0
What is wrong here? 怎么了 any other way to do it?
还有其他方法吗?
试试这个:
var divWidth = $(".RestaurantssubTypeDivClass").css('width');
actually there will be many ul shortlisted in basis of class so you ll have to take widths in array , then you need to precess array : 实际上,在类的基础上会有很多ul入围,因此您必须在array中采用宽度,然后您需要对array进行处理:
Class can be Duplicate. 类可以重复。 Id's are Unique.
ID是唯一的。
var divWidth = [];
$(".RestaurantssubTypeDivClass").each( function(){
divWidth.push( $(this).width());
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.