我试图使元素在单击时消失,元素是动态的。
$("#toast-container").on("click", "div.toast", function() {
$(this).fadeOut("fast", function() {
$(this).remove();
});
});
我已经尝试过仅使用 $(this).remove()
的代码,它可以工作,但使用 fadeOut 则不行。我不知道为什么,但它对我来说看起来绝对没问题
最佳答案
我有一个简单的解决方案。
HTML
<div id="toast-container">
<div class="toast">
Click Me
</div>
</div>
jQuery
$("div.toast").click(function(){
$(this).parent("#toast-container").fadeOut('slow');
// run your another event.
})
查看我的现场演示 jsfiddle
关于javascript - 使用此选择器的 Jquery fadeOut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35001470/