删除剩下的元素
remove the element that's leaved
我有 mouseleave 事件。当我离开该元素时,我不想删除我从中删除的那个元素(如果这有意义的话)。下面的示例,以及我尝试过的。我想我不能那样做,因为那不是它的工作方式(我猜),但是正确的方法是什么?大气压我不能使用像这样的选择器:
$('#wrapper').remove()
而不是
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove());
alert('Mouse leaved and wrapper should be removed');
});
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove);
alert('Mouse leaved and wrapper should be removed');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">asdcasdcasd</div>
remove()
不是 属性 的方法。使用 remove()
而不是 remove
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove());
alert('Mouse leaved and wrapper should be removed');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">asdcasdcasd</div>
我有 mouseleave 事件。当我离开该元素时,我不想删除我从中删除的那个元素(如果这有意义的话)。下面的示例,以及我尝试过的。我想我不能那样做,因为那不是它的工作方式(我猜),但是正确的方法是什么?大气压我不能使用像这样的选择器:
$('#wrapper').remove()
而不是
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove());
alert('Mouse leaved and wrapper should be removed');
});
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove);
alert('Mouse leaved and wrapper should be removed');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">asdcasdcasd</div>
remove()
不是 属性 的方法。使用 remove()
而不是 remove
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove());
alert('Mouse leaved and wrapper should be removed');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">asdcasdcasd</div>