Loop through all elements of a class

By Forrest Smith - Drempd.com

Looping through all elements of a class (.element-class) — and in the example below, restricting this so that it only hits elements within a container element. So if we have a div with an id of ‘container-div’, which has 6 divs with classes named ‘element-class’, this will loop through each and do whatever we want to them. In this case, change the background color:

$('#container-div .element-class').each(function(i, obj) {
$(this).css({"background":"red"});
});