Add Class to First Level LI Elements with jQuery
You can use the \> selector in jQuery to select only the first level of li elements and then add a class to them using the addClass() method. Here's an example: \n\njavascript\n$('ul \> li').addClass('your-class-name');\n\n\nThis will add the class "your-class-name" to all li elements that are direct children of a ul element.
原文地址: http://www.cveoy.top/t/topic/qpk0 著作权归作者所有。请勿转载和采集!