Please tell me how to give a class to an UL object if we have such a structure:

<div class="c1"> <ul> <li class="item-catalog">Text</li> <li class="item-catalog">Text</li> <li class="item-catalog">Text</li> <li class="item-catalog">Text</li> <li class="item-catalog">Text</li> </ul> </div> 

And I can’t touch the block with class c1, I need to make a start only from the LI.item-catalog and through it give the class to the parent, that is, UL.

  • .parent().addClass() - Grundy

2 answers 2

 querySelector('.item-catalog').parentNode.classList.add('class'); 
     $('li.item-catalog').closest('ul').addClass(); 
    • Please write more detailed answers and working code. - user207618
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky