jQuery 选择器:获取 ID 为 two 的 div 元素的所有兄弟元素 - 全面指南
以下是使用 jQuery 完成选取 id 为 two(div 元素) 的所有兄弟元素(前后) 的方法:
- siblings 方法:
$("#two").siblings();
- prevAll 方法:
$("#two").prevAll();
- nextAll 方法:
$("#two").nextAll();
- prevUntil 方法:
$("#two").prevUntil();
- nextUntil 方法:
$("#two").nextUntil();
- siblings、prevAll、nextAll、prevUntil 和 nextUntil 方法可以接受一个选择器作为参数,以进一步过滤匹配的兄弟元素。例如,如果只想选择 class 为 "myClass" 的兄弟元素,可以这样写:
$("#two").siblings(".myClass");
$("#two").prevAll(".myClass");
$("#two").nextAll(".myClass");
$("#two").prevUntil(".myClass");
$("#two").nextUntil(".myClass");
原文地址: https://www.cveoy.top/t/topic/pKZp 著作权归作者所有。请勿转载和采集!