Hello. There is the following markup html
$('.cd-main-nav li').has('ul').addClass('test'); .test { background-color:red; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="cd-main-nav"> <li><a href="#ankor" class="cd-subnav-trigger"><span>О нас</span></a> <ul> <li><a href="#ankor">Пункт №1</a> </li> <li><a href="#ankor">Пункт №2</a> </li> <li><a href="#ankor">Пункт №3</a> </li> <li><a href="#ankor">Пункт №4</a> </li> <li><a href="#ankor">Пункт №5</a> </li> </ul> </li> <li><a href="#ankor">Каталог</a> </li> <li><a href="#ankor">Портфолио</a> </li> <li><a href="#ankor">Контакты</a> </li> <li><a href="#ankor" class="cd-subnav-trigger"><span>Список</span></a> <ul> <li><a href="#ankor">Пункт №6</a> </li> <li><a href="#ankor">Пункт №7</a> </li> <li><a href="#ankor">Пункт №8</a> </li> <li><a href="#ankor">Пункт №9</a> </li> <li><a href="#ankor">Пункт №10</a> </li> </ul> </li> </ul> Question: how to assign a new class (say .test as in the example) to the tag A, which is in the LI, which has a nested UL list, and precedes this UL.
Now the class is assigned to the entire item LI.
How many did not fight - does not go. Help to cope with this task.