わかりました、これにはいくつかのコードが含まれますが、カスタム イベントが機能する可能性があります。ここでは、起動するカスタムの「specialEvent」と、目的を実行するための「trackChanges」関数があります。
ここで変更された内容に応じてクラスを追加するだけの「トラッカー」関数をフィドルで作成しました: http://jsfiddle.net/DsSQd/1/ そして以前に「トラッカー」要素で見られた長さを追跡します-これでグループの親の場合。少し醜いですが、そこでやりたいことができます。私の場合、親ラッパーでグループの長さを追跡し、長さが変更されたかどうかに応じてクラスを追加するだけです。変更されていない場合は、イベントを発生させる要素。
// custom event handler
$(document).on('specialEvent', '.special, .changerthing, .friendly>.specialalso', function () {
trackChanges(this, $(this).parent(), $(this).parent());//react to the change
});
// event where I trigger the handler
$('#wrapperToBindTo').on('click wacked', '.changers,.special,.changerthing', function () {
$(this).trigger('specialEvent');
});
// event where I trigger the handler
$('.friendly').on('click', '.specialalso', function () {
var me = $(this);
me.clone().appendTo($(this).parent()).text(me.text() + ' Copy of:' + me.index()); //add one
me.parent().find('.specialalso:last').trigger('specialEvent'); //fire special event
});
たとえば、次の関数を追加できます。
//added to show a remove, then trigger that cascades
$('#wackFriendly').click(function(){
$('.friendly>.specialalso').last().remove();
$('.friendly>.specialalso').last().trigger('wacked');
});
次に、ここに示すように処理します: http://jsfiddle.net/DsSQd/2/