我有一些JQuery获取列表中的第一列和第二列,并根据两者之间的最大高度更改元素的高度。这很有效,确保标题高度相同,但是如果两列中的任何一列都是空的,我试图去掉一个跨度。到目前为止,这是我的工作脚本:
var $sections = $('.section-link'); //the column box
$sections.filter(function() {
return $(this).css('display') == 'block'; //aslong as the column box is visible
}, ':nth-child(2n-1)').each(function (index, value) { //get 1st to 2nd column boxs
var $this = $(this);
var $els = $this.nextAll(':lt(1)').addBack(); //get both
var sectionheight = new Array(); //empty section height
$els.each(function (index, value) {
var value = $(this).find('.section-title').height();
sectionheight.push(value);
var value2 = $(this).find('.was-price-container'); //this is the span that I'm trying to hide
if($.trim(value2.html()) != "") {
//here we have identified the span is empty and now I need to find a way to hide it if not in either boxes in second of first column
}
});
var newsectionheight = Math.max.apply(Math, sectionheight);
$els.find('.section-title').height(newsectionheight);
});
这适用于高度,但是如果此列的跨度was-price-container
包含内容,并且它确实没有删除此列或前一列或最后一列上的跨度,我就会陷入困境。
- title - | - title -
- span - | - span - < both columns have the span so keep it
----------------------
- title - | - title -
- span - | - - < only one column has the span so keep both
----------------------
- title - | - title - < neither have span so remove it
----------------------
- title - | - title -
- - | - span - < only one column has the span so keep both
----------------------
这样做的原因是所有盒子都保持相同的高度。
任何建议都非常感谢。
答案 0 :(得分:0)
不知道这是否适合您。但是你不能只使用带有jQuery的:empty选择器来移除空跨度。
$('span:empty').remove();
或者将它与选择器一起使用
$('.was-price-container span:empty').remove();