Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Get.each()prev元素高度_Jquery_Loops_Each - Fatal编程技术网

Jquery Get.each()prev元素高度

Jquery Get.each()prev元素高度,jquery,loops,each,Jquery,Loops,Each,如何获取循环中上一个元素的高度?这是我的密码 jQuery(".wrap").each(function(index, element) { var id = jQuery(this).data('id'); var wrapper_height = jQuery('.wrap_' + id).outerHeight(true); }); 我需要迭代的第一个元素的高度,然后是之前所有元素的高度 我有两个类名为wrap的div,迭代时需要第一个wrap项的高度,下一个相同(当第三个元素

如何获取循环中上一个元素的高度?这是我的密码

jQuery(".wrap").each(function(index, element) {
  var id = jQuery(this).data('id');
  var wrapper_height = jQuery('.wrap_' + id).outerHeight(true); 
});
我需要迭代的第一个元素的高度,然后是之前所有元素的高度

我有两个类名为wrap的div,迭代时需要第一个wrap项的高度,下一个相同(当第三个元素在循环中迭代时,需要第二个元素的高度)

当第四个项目在每个迭代时,我需要第三个迭代的项目高度

标记:
Some content Some content


有什么帮助吗?

请考虑使用以下方法捕获上一项:

var prev=jQuery(“.wrap”)[index-1]

编辑:

由于您的标记,您可以使用:

var prev=jQuery(this.prev()

文档中所有以前的元素或所有以前的子元素?请显示您的标记,并进行更新以准确描述您要选择的元素。我更新了问题。没有标记…现在检查是否可以?