To add a class only to the parent levels of 'li' elements, you can use the 'parent()' method in jQuery. Here's an example:

$(document).ready(function() {
  $('li').parent('ul').addClass('your-class-name');
});

In this code, $('li') selects all 'li' elements, and then parent('ul') selects their parent 'ul' elements. Finally, addClass('your-class-name') adds the class 'your-class-name' to the selected 'ul' elements, which are the parent levels of the 'li' elements.

Make sure to replace 'your-class-name' with the name of the class you want to add.

How to Add Class to Parent UL Elements of LI Elements in jQuery

原文地址: http://www.cveoy.top/t/topic/qpkZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录