別の私の質問 (これ: How to make children auto fit the parent's width only with CSS? ) への回答に基づいて、パフォーマンスに関する問題を解決するための最良の jQuery アプローチはどれかを考えています。
ブロック 1: 必要に応じてすべての DOM 要素を検索します。
$("div.parent a").css("width", $("div.parent").width() / $("div.parent a").length - 2);
ブロック 2: DOM の子のみを検索し、each()、parent()、および siblings() を使用します。
$("div.parent a").each(function() {
$(this).css("width", $(this).parent().width() / $(this).siblings().length - 2);
});
ブロック 3: 最初に DOM の親を見つけ、each() を使用して、コンテキストに基づいて子を見つけます。
$("div.parent").each(function() {
$("a", this).css("width", $(this).width() / $("a", this).length - 2);
});
誰かがテストしたい場合のフィドルは次のとおりです。http://jsfiddle.net/ErickPetru/6nSEj/3/
では、どのブロックが良いでしょうか?なぜ?