// Which block below is better regarding performance and why?
/* Block 1: find all DOM elements when needed.
$("div.parent a").css("width", $("div.parent").width() / $("div.parent a").length - 2);
*/
/* Block 2: find only DOM children, use each(), parent() and siblings().
$("div.parent a").each(function() {
$(this).css("width", $(this).parent().width() / $(this).siblings().length - 2);
});
*/
/* Block 3: find DOM parent first, use each() and find children based on context.
$("div.parent").each(function() {
$("a", this).css("width", $(this).width() / $("a", this).length - 2);
});
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!