jQuery 设置元素的高度

标签 jquery

如何使用each()方法将内部div的高度设置为其父级?

<div class="box">
    <div class="inner">Stuff</div>
</div>
<div class="box">
    <div class="inner">Stuff</div>
</div>
<div class="box">
    <div class="inner">Stuff</div>
</div>
<div class="box">
    <div class="inner">Stuff</div>
</div>

这似乎不起作用:

$('.box').each(function(){
    var $this = $(this);
    var $inner = $this.find(".inner");
    $inner.height( $this.height );

});

最佳答案

要获取元素的高度,您必须使用 method 高度():

$('.box').each(function(){
    var $this = $(this);
    var $inner = $this.find(".inner");
    $inner.height( $this.height() );
});

关于jQuery 设置元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10507853/

相关文章:

javascript - 使用 javascript(或 jQuery)选择和操作 CSS 伪元素,例如::before 和::after

javascript - Raphael:将 ".data"链接到 raphael.js 元素

javascript - 检查最新的div

带有数组的 Javascript/jQuery 动画

javascript - canvas setDimension() 破坏了图形的拖动功能

javascript - HTML5 Javascript 对象已被点击

javascript - IE 出现 'focus' 事件问题

jquery - 如何通过类和特定名称属性查找元素?

jQuery 选择器性能

jquery - 我们如何将跨度添加到 ul 内的文本,即 jquery 或 css 中的 li 之外