2013-08-29 3 views
0

요소 높이를 55 개 이상으로 결정하려고합니다.이 경우 래핑 div는 55 픽셀로 축소되고 "Read-more" 링크가 나타납니다.jquery 각 함수에서 .next()를 사용할 수 없습니다.

문제는 DOM 탐색기 .next() 및 .hide()가 각 함수 내에서 작동하지 않는다는 것입니다. 나는 요소의 높이를 얻고 있는데, 나는 콘솔에 그것들을 로깅하고있어 다른 값을 얻는다. 하지만 IF 문장을 사용하여 작고 작은 요소에서 .read-more 링크를 숨기면 작동하지 않습니다.

여기 내 피들 http://jsfiddle.net/eKDUe/입니다. 완전히 잃어 버렸습니다. 나는 누군가가 도울 수 있기를 희망한다!

readMore.prev('p').each(function(index) { 

var deg = $(this).height(); 
console.log(deg); 
if (deg < 55){ 
    var as = $(this); 
    var as2 = as.next(); 
console.log(as2);  
} 
}); 


readMore.on('click', function(){ 
$this = $(this); 
var current = $this.prev(); 
console.log(current); 
    if(current.height() < 55){ 

     current.css('height', 'auto'); 
    $this.html('Dölj'); 
    }else{ 
    current.css('height', '53px'); 
    $this.html('Läs mer'); 
    } 
}); 
+2

은'readMore' 무엇 Fiddle? –

답변

1

해보십시오 뭔가 glike

readMore = $('.read-more').hide() 
readMore.filter(function(){ 
    return $(this).prev().height() > 55; 
}).show() 

데모 :

+0

코드를 수정하면 수정이됩니다! 도움을 많이 주셔서 감사합니다! P 요소에 도달하도록 '어린이'탐색기를 추가했습니다. 다시 감사합니다! 'readMore = $ ('. read-more'). 숨기기()' 'readMore.filter (function() { 'return $ (this) .prev(). children(). height 55;' '}). show()' –

관련 문제