2015-10-07 98 views
0

我想要使用jquery获取.more类和.popovercontent div的宽度和高度。 popover-content类的宽度是动态的,它可以改变,因为我从我的数据库中获取宽度。 Iam由此得到下面的分区。所以我想知道如何使用这个如何在jQuery中访问此内部的宽度和高度

console.log(this); 

得到的宽度和高度它显示如下的结果

<div id="picture1-more4" class="more more32 ltr-slide bgblack" style="top: 288px; left: 549px; z-index: 1; width: 32px; height: 32px;"> 
<div class="imgButton imgButtonDrag imgButtonDrag imgButtonDrag imgButtonDrag imgButtonDrag imgButtonDrag imgButtonDrag imgButtonDrag moreblack"></div> 
<div class="popover-inner red" style="margin-left:50px;"> 
<div class="arrow-right3" style="display: inline-block !important; border-left-width: 10px; border-left-style: solid; border-left-color: green; border-top-width: 10px; border-top-style: solid; border-top-color: transparent; border-bottom-width: 10px; border-bottom-style: solid; border-bottom-color: transparent; position: absolute; top: 50%;"></div> 
<h4 class="popover-title"><a href="" target="self">Garden</a></h4> 
<div class="popover-content" style="width:400px;"><p>To view details about either the Security or Maintenance section, click the heading or the arrow next to the heading to expand or collapse the section. If you dont want to see certain types of messages, you can choose to hide them from view. </p></div> 
</div></div> 

回答

1

那么问题是,你需要指定什么$(this)是。 正如你可以在我的小提琴中看到的,我循环遍历每一个div,这意味着$(this)现在是它在那一刻循环的“div”。

http://jsfiddle.net/4oq27b3r/

但为什么要用$(this)如果你知道你想从宽度类? 正如其他人说,这是比较容易的方式:

$('.more').width() 
$('.popover-content').width() 
+0

感谢您的解决方案为我工作。 –

0

如果你正在使用jQuery,你可以试试这个

VAR WIDTH = $( '试验')宽度();

var height = $('。test')。height();

+0

我已经知道了这个标签,但它不会工作,因为我想用“这个” –

0

您可以使用如下

$(this).width() 
$(this).height() 
+0

我想类的高度和宽度的宽度和高度和popover-content –

+0

请为您的回答添加一些解释 –