I am attempting to dynamically set the width of several child elements using jQuery. Here is what I am trying to achieve:
- Obtain the count of the desired containers (since there will be multiple instances of the .steps-container class in the DOM)
- Iterate through their children
- Set the width of their children using the formula: width = 100 / number of children
This is the code I have:
$(document).ready(function() {
var setStepsWidth = function(stepsContainer) {
var el = stepsContainer,
count = stepsContainer.length,
childrenCount = 0;
for( var i = 0; i < count; i++ ) {
childrenCount = el[i].children.length;
var containerChildren = el[i].children;
console.log(containerChildren);
for(var j = 0; j < childrenCount; j++) {
//test to see if it's working
childrenCount[j].css('background-color', 'red');
}
}
};
setStepsWidth($('.steps-container'));
});
When running the code, I encounter an error: "Uncaught TypeError: Cannot read property 'css' of undefined"
What could I be overlooking?