Your code is absolutely correct and it does not need to be written twice. Just use jQuery for the class name 'section' as shown below:
$("p").animate({opacity: 0}, 0); $("div[class^='section']").each(function() { $(this).children().each(function(i) { $(this) .delay(100 * i) .css('display', 'block') .animate({opacity: 0}, 0) .animate({opacity: 1, marginLeft: "+=10px"}, 200) }); });
"div[class^='section']" selects all classes starting with a section (for example, section1, section2 ..).
source share