jQuery: Adding Class to First Level LI Elements
You can use the '>' selector in jQuery to select only the direct children of an element. In this case, you can use the '>' selector to select only the first level 'li' elements and add a class to them. Here's an example:
$('ul > li').addClass('your-class-name');
This code will add the class 'your-class-name' to all the first level 'li' elements inside the 'ul'. It will not add the class to the 'li' elements that are nested inside other 'li' elements.
原文地址: http://www.cveoy.top/t/topic/qplg 著作权归作者所有。请勿转载和采集!