使用jQuery完成选取id为twodiv元素的所有兄弟元素前后!所有方法
以下是使用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");
``
原文地址: http://www.cveoy.top/t/topic/h1XN 著作权归作者所有。请勿转载和采集!