委任された形式のイベント処理を使用できますが、疑似イベントでは機能しないhover
ため、mouseenterイベントとmouseleaveイベントの両方を監視する必要があります。
$("#sortable").on("mouseenter", "li", function() {
// mouse over code here
$(this).find(".close").show();
});
$("#sortable").on("mouseleave", "li", function() {
// write your hover out code here
$(this).find(".close").hide();
});
またはよりコンパクトな形式:
$("#sortable").on({
mouseenter: function() {
// mouse over code here
$(this).find(".close").show();
},
mouseleave: function() {
// mouse leave code here
$(this).find(".close").hide();
}
}, "li");
これが機能する方法は、マウスイベントがパーツチェーンをバブルアップするため、この委任された形式は、子タグで発生したイベントを親から.on()
監視し、目的のイベントに一致したときにコールバックをトリガーします。#sortable
li