You need to add a class using jQuery to each link "Section Name" of the first line of nesting, regardless of the nesting levels of the tree. Simple language - you need to select only the name of each section. The pseudo-classes :first and :first-child do not help, since they add a class to either the first element or all links in the tree. Here is an example.

1 answer 1

A similar question, only there it was not necessary to add the class, but to display it ( link ).

Brute force solution:

 $(document).ready(function() { var parent = $('ul:first'), highlight = $('li a', parent); // ссылки со всех линий вложенности highlight = highlight.filter(function(){ return !$('ul', parent).has($(this)).length; // проверка вложенности }); highlight.addClass('link'); }); 

http://jsfiddle.net/he7q3hk5/