The index of widgets counts up from 0, so I needed to fix every child whose index is a multiple of 3.
My original solution looked like this, and only applied to the 4th widget:
$(".home_widgets .widget:eq(3)").css("margin-left", "0");
The improved version, good for however many widgets I might add:
$(".home_widgets .widget").each(function(index){
if(index % 3 == 0) {
$(this).css("margin-left", "0");
}
});
My references were the jQuery .each() API, and the Web Developers Notes Javascript Tutorial on arithmetical operations; see Modulus. I was really pleased with myself for figuring that out.
This blog post is reposted from my technical/professional blog, dbwebwork.
Photo credit: Creative Commons by Winfried Bruenken. Source: Worldnews
No comments:
Post a Comment