私はmouseleaveイベントを持っています。私が要素を去るとき、私はマウスが置かれた要素を取り除くことはしません(これが意味をなさない場合)。以下の例と私が試したこと。それはそれがどういう仕組みではないから(私は推測する)、そうすることができないと思いましたが、それを行うにはどのような方法がありますか? Atm。leavedの要素を削除する
$('#wrapper').remove()
むしろ
私はmouseleaveイベントを持っています。私が要素を去るとき、私はマウスが置かれた要素を取り除くことはしません(これが意味をなさない場合)。以下の例と私が試したこと。それはそれがどういう仕組みではないから(私は推測する)、そうすることができないと思いましたが、それを行うにはどのような方法がありますか? Atm。leavedの要素を削除する
$('#wrapper').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>
$(document).on('mouseleave', '#wrapper', function(e) {
console.log($(this).remove());
alert('Mouse leaved and wrapper should be removed');
});
以下の方法ではない特性である:私は次のようにセレクタを使用することはできません。使用
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>
あなたがあなたの最初の2つのセクションでは、それだけではない 'を持っているスニペット、に記載されている' .removeを() '、使用しているときあなたのコードが動作します.remove'。 – Herohtar