2014-01-29 3 views
0

목록에서 첫 번째와 두 번째 열을 가져 와서 둘 사이의 최대 높이에 따라 요소의 높이를 변경하는 JQuery가 있습니다. 이 작품은 위대한 제목의 동일한 높이가 있는지 확인하지만 두 열 중 하나에서 비어있는 경우 스팬을 제거하려고합니다. 여기에 지금까지 내 작업 스크립트입니다 : 이것은이 칼럼의 범위 was-price-container이 내용이 있는지 확인하는 높이 그러나 나는 갇히지하고 있습니다에 대한 제대로 작동하고 할 않는 경우에이 칼럼의 범위를 제거하거나되지첫 번째와 두 번째 열이 모두 비어 있으면 스팬을 제거하십시오.

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); 
}); 

이전 또는 마지막 열.

- 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

이것이 당신을위한 해결책 일 수 있는지 모르겠다. 하지만 빈 스팬을 제거하기 위해 빈 선택기를 jQuery와 함께 사용하면 안됩니까?

$('span:empty').remove(); 

아니면 선택

$('.was-price-container span:empty').remove(); 
+0

감사와 함께 사용, 그건 아마 내 if 문보다 훨씬 쉬울 것, 그러나 가장 큰 문제는 이전 또는 경우에 심화 한 후 열을 식별하는 데 그것 첫 번째 또는 두 번째, 둘 다 비어있는 경우에만 스팬을 제거합니다. –

+0

HMTL을 공유 할 수 있습니까? 요소를 언제, 어떻게 처리해야하는지 파악하는 것이 훨씬 쉬울 것입니다. –

+0

html을 보려면 여기를 참고하십시오 : http://jsfiddle.net/2d8Tk/ html은 약 10-20 div의 목록에있는 단순한 2 개 divs입니다. –

관련 문제