paranitips

Never stop learning! がモットーのゆるふわエンジニアブログ

よく使うjQueryでのcssセレクタまとめ

jQueryオブジェクトでcssセレクタを多用するのでその備忘録です。

var target;
$('.select').click(function() {
    target = $(this); // .selectそのもの
    target = $(this).parent(); // .selectの親要素
    target = $('.child',this); // .selectの子要素.child
    target = $(this).children(); // .selectの子要素
    target = $('.child .grandchild',this); // .selectの孫要素.grandchild
    target = $('+ .brother',this); // .selectの直後の兄弟
});

あと、$("hoge, fuga")みたいにコンマ(,)区切りでターゲットを追加できます。

参考