I'm not sure what your HTML looks like, but if you're trying to add a class name to each level, I would use Y.each
and Y.one
like so:
var levels = [2, 3, 4, 5, 6, 7, 8, 9];
Y.each(levels, function (level) {
var node = Y.one(".level"+level);
if(node) {
node.get('parentNode').addClass('category_level' + level);
}
});
This would pass in a linter as well as not fail if Y.one('.level199')
does not exist.
This will work for multiple level nodes:
var levels = [2, 3, 4, 5, 6, 7, 8, 9];
Y.each(levels, function (level) {
Y.all(".level"+level).each(function (node) {
node.get('parentNode').addClass('category_level' + level);
});
});