2016-05-19 13 views
-1

私はあなたがプラスをクリックすることで人物を追加することができ、フォームを構築し、(明らかに)マイナスをクリックすることで、それらを削除次の要素を見つけてクラスを追加するにはどうすればよいですか?

ています、私はあなたのためのより良いビューを作成するためにスクリーンショットを持っている: enter image description here

の場合私はこのような何かwritinてきた私は名前PERSON2とEメールの人物2を削除したいキーを押します。それはparentのために働いている

$('.fa-minus-circle').click(function() { 
    $(this).parents('.form-input-wrap').removeClass('show').addClass('hidden'); 
    $(this).closest('.form-input-wrap', 'div').addClass('test'); 
}); 

をして、それはそれを隠しますが、どのように私はの隣に.form-input-wrapにアクセスします

答えて

2

以下のようにnext()メソッドを使用できます。

$(this).closest('.form-input-wrap').next('.form-input-wrap').addClass('test'); 
0

親フォーム入力ラップでは、jQueryのnext関数を使用できます:)。

$('.fa-minus-circle').click(function() { 
    var $parent = $(this).parents('.form-input-wrap:first'); 
    $parent.removeClass('show').addClass('hidden'); 
    $parent.next('.form-input-wrap', 'div').addClass('test'); 
}); 
関連する問題