.active {
color: red;
}
const startFrom = '.link';
const parent = 'li';
const child = 'a';
const className = 'active';
$(startFrom).parents(parent).children(child).addClass(className);
// или
for (
let el = document.querySelector(startFrom);
el = el.parentNode.closest(parent);
el.querySelectorAll(`:scope > ${child}`).forEach(n => n.classList.add(className))
) ;