stopPropagation()
イベントフォローを防ぐために使用する必要があります。
function Infocus(e) {
e.stopPropagation();
// your code
}
function Outfocus(e) {
e.stopPropagation();
// your code
}
.stopPropagation()について読む
あなたはこのようなことをすることができます:(満足できないかもしれません)
$("#parent").live({
mouseenter: Infocus,
mouseleave: Outfocus
});
$("#children").live({
mouseenter: Infocus,
mouseleave: Outfocus
});
function Infocus(e) {
if(this.id == 'parent') {
$(this).css('background', 'yellow');
} else if(this.id == 'children') {
$(this).css('background', 'green');
$(this).parent().trigger('mouseleave')
}
}
function Outfocus(e) {
if(this.id == 'parent') {
$(this).css('background', 'transparent');
} else if(this.id == 'children') {
$(this).css('background', 'transparent');
$(this).parent().trigger('mouseenter')
}
}
デモ