单击按钮,直到元素可见(单击更多按钮)



我希望在jquery中单击加载更多按钮,直到屏幕上显示一个元素。按钮loadmore调用ajax在屏幕上添加元素。我正在尝试做while循环,但它不起作用,导致浏览器崩溃。谢谢你的建议!

// new-element not visible at first, I have to click the button load more many times for it to show
do{
// clicking button load more (ajax call adding dynamically more elements on the screen)
$('.button-load-more').click();
}while($('.new-element').length == 0 )

我希望它能帮助你。

$(document).on('click','.button-load-more',function(e){
e.preventDefault();
$.ajax({
success:function(data){
$('.button-load-more').hide().prop('disabled',true);
}
});
});

最新更新