タグ別アーカイブ: children

jQuery 子要素を検索する、取得する方法:children(), find()など

全ての子孫要素から取得する.find()

$(“#parent”).find(‘.child-image’);

直下の子要素を取得する.children()

$(“#parent”).children(‘img’);

セレクタを使って子要素を取得する

$(“#parent div”);

子要素のn番目の要素を指定

$(“#parent p:first”).css(“color”, “red”);

$(“#parent p:last”).css(“color”, “red”);

$(“#parent p:nth-child(2)”).css(“color”, “red”);