Skip to content
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • stream
    • projects
    • website design
    • code notes
Blog Web Dev Loop through all elements of a class

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"});
});
Posted on October 29, 2014August 26, 2022 in Web Dev

drempd | san diego, ca


home contact

adventures san diego projects stream website design

portfolio resume san diego web design freelance web designer

custom web design responsive web design website maintenance