2013-10-12 4 views
0

내 메뉴 중 하나에서 jQuery의 has 메서드를 사용하여 현재 <li><ul>이 있는지 확인하려고합니다. 예인 경우 표시하고 그렇지 않으면 li을 숨 깁니다.잡히지 않은 TypeError : 개체 # <HTMLLIElement> 메서드 없음 'has'

하지만이 오류를 얻고있다 has를 사용하는 경우 :

Uncaught TypeError: Object # has no method 'has'

내 코드 : this는 jQuery를 객체가 아니기 때문에

$('nav ul li').click(function() { 
    console.log(this.has('ul')); //Checking 
    if ($(this).children('ul').is(":visible")) { 
     $(this).children('ul').slideUp(250); 
    } else { 
     $(this).children('ul').slideDown(250); 
    } 
}); 
+0

jQuery 버전이 1.4 미만입니까? –

+0

'has'는 jquery 메소드이지만 DOM 요소에서 호출하고 있습니다. – elclanrs

+1

console.log ($ (this) .has ('ul'))이어야합니다. – Jeffpowrs

답변

3

나중에 $(this)을 할 이유입니다. 여전히 $(this).has('ul')해야합니다.

토글 링 부분을 $(this).children('ul').slideToggle(250);으로 단순화 할 수도 있습니다.

관련 문제