2016-07-14 6 views
0

jqueryスペクトルカラーピッカーを使用しています。変更イベント内でスペクトルセレクタを取得する方法はありますか?jQueryスペクトルカラーピッカー

クラス(hap-ch)で複数の要素にスペクトルを適用すると、アクティブセレクタインスタンスを取得できますか?

<input id="playerBgColor" class="hap-ch"> 
<input id="playerBgColor2" class="hap-ch"> 
<input id="playerBgColor3" class="hap-ch"> 

$(".hap-ch").spectrum({ 
    change: function(color) { 
     //how to get playerBgColor id here? 
    }, 
}); 

私は、私はこのような個別のスペクトルを適用することができます知っている:

$("#playerBgColor ").spectrum({ 
    change: function(color) { 

    }, 
}); 

しかし、私は最初の例のように、複数のスペクトルのために、このコードを再利用できるかどうか知りたいと思いました。

+0

あなたは 'デモfiddle'を追加してもらえますか? –

答えて

1

私はちょうど周りに遊んだし、うん、$(this)changeの中に使用することができます、これは現在のinput elementを参照します。

$(".hap-ch").spectrum({ 
    change: function(color) { 
      alert($(this).attr('id')); //there you get the id 
    }, 
}); 

DEMO HERE

関連する問題