I have this which performs an action on all elements with the class names ‘class1’ and ‘class2’. How would be the better way to code it so I don’t just have to repeat the code multiple times (class names don’t always have a number after it)?
var elements = getElementsByClassName(document, ‘class1’),
elementsLength = elements.length,
i;
for (i = 0; i < elementsLength; i += 1) {
// etc.
}
var elements = getElementsByClassName(document, ‘class2’),
elementsLength = elements.length,
i;
for (i = 0; i < elementsLength; i += 1) {
// etc.
}