[英]Remove first in a list only works first time
I have a list of results, and I want to pop the most recent one with a button click like this: 我有一个结果列表,我想通过单击按钮来弹出最近的结果:
//clear most recent
$('#clear-most-recent').on('click', function () {
$('#output').children().first().hide(800).done().remove();
});
but it only works the first time. 但只能在第一次使用。 The error is
uncaught TypeError, ...is not a function
. 错误是
uncaught TypeError, ...is not a function
。 I'm guessing each subsequent call tries to access the now-removed element. 我猜每个后续调用都尝试访问现在已删除的元素。
link to project on jsbin (be warned, its ugly): https://jsbin.com/lodobaj/edit?html,output 链接到jsbin上的项目(警告,这很丑): https ://jsbin.com/lodobaj/edit?html,输出
Use callback function to remove: 使用回调函数删除:
$('#clear-most-recent').on('click', function () {
$('#output').children().first().hide(800, function(){
$(this).remove();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.