There is no need of total traversing back to the parent one after the other in a hierarchy, you can just do use parents()
instead of parent()
in this way
$('.selected').parents('ul.lowerMenu').children(:first-child').addClass('selected');
Try it this is working!!