모든 하위 요소를 비우고 동일한 클래스를 사용하지만 별도 요소 내에 요소를 적용합니다.jQuery empty() 콜백이 실행되지 않습니다.
이 empty()
함수의 콜백 함수가 실행되지 않습니다. 이 클래스/콜백 문제로 뭔가 빠졌습니까?
$('.commentsButton').click(function(e){
e.preventDefault();
if ('.openComments').length) {
$(this).closest('.box').removeClass(openComments);
$('.commentsBox').empty(function(){
$(this).closest('.box').find('.commentsBox').load('url.com');
$(this).closest('.box').addClass(openComments);
});
} else {
$(this).closest('.box').find('.commentsBox').load('url.com');
$(this).closest('.box').addClass(openComments);
}
});
<div class="box">
<a class="commentsButton" href="#"></a>
<div class="commentsBox"></div>
</div>
<div class="box">
<a class="commentsButton" href="#"></a>
<div class="commentsBox"></div>
</div>
는 http://api.jquery.com/empty/에 대한 설명서를 읽는다면, 그것은 말한다 : '이 함수는 인수를 허용하지 않습니다'. – putvande
@ putvande 쓰레기. 그 부분을 놓친 ... 위의 방법을 수행 할 수 있습니까? – canacast
empty()는 동기 메서드이므로 콜백이 필요하지 않습니다. – adeneo