2012-09-18 5 views
0

내 사이트에 회전식 메뉴가 있으며 요소가 없으면 jquery가 충돌하는 것 같습니다.요소에 하위 요소가있는 함수가있는 경우

$('.gallery-viewport-twobedroomapartment').carousel('#simplePrevious', '#simpleNext'); 

는 UL이 LI는 다음 기능을 실행이 포함 된 경우 말할 수 있는가 ... 요소가없는

내 HTML 출력은 ...

<section class="gallery-viewport-twobedroomapartment viewer"> 
    <ul> 
    </ul> 
    <a id="simplePrevious"><img alt="Left Arrow" src="_includes/images/larr.png"></a> 
    <a id="simpleNext"><img alt="Right Arrow" src="_includes/images/rarr.png"></a> 
</section> 

입니다 그리고 내 jQuery를 무엇입니까?

답변

1
if($('.gallery-viewport-twobedroomapartment ul > li').length > 0) { 
    $('.gallery-viewport-twobedroomapartment').carousel('#simplePrevious', '#simpleNext'); 
} 
0
var liCount = $('ul li').length; 

if (liCount > 0) { 
    $('.gallery-viewport-twobedroomapartment').carousel('#simplePrevious', '#simpleNext'); 
} 

붐!

0

당신은 .children()length를 사용할 수 있습니다 JQuery와 수집 사용 length의 모든 요소가있는 경우

if ($(".gallery-viewport-twobedroomapartment").children("ul").children("li").length > 1) 
    $('.gallery-viewport-twobedroomapartment').carousel('#simplePrevious', '#simpleNext'); 
1

알고.

if ($(elements).length) { 
    // there are elements 
} 
관련 문제