すべての兄弟(ラジオボタングループのラベル)から属性'rel'の値を配列に取得する方法を知っている人はいますか?
私はこのようなことを試しましたが、明らかに機能しません:
<label rel="option_local" class="type_radio" for="type_3">
<input type="radio" checked="checked" value="3" id="type_3" name="type" />
Local</label>
<label rel="option_remote" class="type_radio" for="type_2">
<input type="radio" value="2" id="type_2" name="type" />
Remote</label>
<label rel="option_html" class="type_radio" for="type_1">
<input type="radio" value="1" id="type_1" name="type" />
HTML</label>
$('.type_radio').click(function() {
var r = $(this).attr('rel');
var arr = $(this).siblings().attr('rel');
$.each(arr, function(k, v) {
$('.' + v).addClass('dn');
});
$('.' + r).removeClass('dn');
return false;
});
特定のトリガーの「rel」属性を参照し、それらから特定のクラスを削除するクラスを持つ要素をループしようとしています。次に、このクラスを、選択したクラスを参照するクラスに適用します。
すべてのラベルにはクラス'type_radio'があります。