忘れがちのjQueryのセレクタ方法
each
例の意味:ddタグの中のid='set_size' の全部のclass='swatchOuter' の要素を走査し
それぞれの一番目のdivのclassをクリアーしてから'swatchAvailable'に変更する。
$('dd#set_size .swatchOuter').each(function (k,v){ $("div:first",$(v)).removeClass(); $("div:first",$(v)).addClass('swatchAvailable'); });
function の中にthisの要素をさらに指定
例の意味:ddタグの中のid='set_size' の一番目のclass='swatchOuter' の要素一番目のdivのclassをクリアーしてから'swatchAvailable'に変更する。
$('dd#set_size .swatchOuter:first').click(function(){ $("div:first",$(this)).removeClass(); $("div:first",$(this)).addClass('swatchAvailable'); });