【发布时间】:2021-08-30 03:13:00
【问题描述】:
我想为这个“menu-item-has-children”类中带有“ul”的每个“FIRST”元素添加一个类“my-class-to-add”。
我用这个试过,但只添加了第二个菜单。感谢您的帮助。
<script>
jQuery(document).ready(function ($) {
$('.nav-menu .menu-item-has-children ul:eq(1)').each(function() {
$(this).addClass('my-class-to-add');
});
});
</script>
【问题讨论】:
-
请发布您的尝试minimal reproducible example,使用
[<>]sn-p 编辑器记录输入和预期输出。 -
这能回答你的问题吗? How to select first child with jQuery?